#include<iostream> using namespace std; long long quick(long long a,long long b,int c) { int ans=1; a=a%c; while(b!=0) { if(b&1) ans=(ans*a)%c; b>>=1; a=(a*a)%c; } return ans; } int main() { long long a,b; while(cin>>a>>b) { cout<<quick(a,b,10)<<endl; } return 0; }