for(;l=readline();)print(Math.pow(/. /(l),/..$/(l)%4+4)%10)