#include #include #include #include #include #include #include #include #include const long long INF = 1e6+7; const long long MOD = 1e9+7; const double PI=acos(-1); using namespace std; int main(){ string ns,ms; cin >> ns >> ms; reverse(ns.begin(),ns.end()); reverse(ms.begin(),ms.end()); int n=(int)(ns[0]-'0'); int m=(int)(ms[0]-'0'); if(ms.size()>=2){ m+=10*(int)(ms[1]-'0'); } if(ms.size()>=3){ m+=100*(int)(ms[2]-'0'); } if(ms.size()>=4){ m+=1000*(int)(ms[3]-'0'); } if(ms.size()>=5){ m+=10000*(int)(ms[4]-'0'); } long long now=1; vector a; for(long long i=0;i<30;i++){ now*=n%10; now%=10; a.push_back(now); } int dist=1; for(int i=0;i