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