a[2],c;main(f){for(;read(0,&c,1);)c-10?a[f]=a[f]%10*10+c-48:f--;c=!putchar((f=pow(a[1]%c,*a%4+!!*a*4))%c+48);}