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