char s[9999];a;main(b){a=!printf("%d",(a=pow(s[strlen(gets(s))-1]-48,(a=atoi((b=strlen(gets(s))-1)?s+b-1:s))%4+(b||a)*4))%10);}