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