#include<iostream> |
#include<string> |
using namespace std; |
int main(){ |
int m; |
int n; |
while (cin>>m>>n){ |
int gewei; |
gewei = m % 10; |
if (gewei == 0){ |
cout<<0<<endl; |
continue ; |
} else if (gewei == 1){ |
cout<<1<<endl; |
continue ; |
} else { |
int temp = gewei; |
if (!(n % 4)){ |
for ( int i = 2; i <= 4; i++){ |
temp *= gewei; |
} |
} |
for ( int i = 2; i <= n % 4; i++){ |
temp *= gewei; |
} |
cout<<temp % 10<<endl; |
} |
} |
} |