#include <iostream>
#include <iomanip>
#include <cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int a,b;
while(cin>>a>>b){
a%=10007;
long long int sum=1;
for(int i=0;i<10007;i++){
sum*=a;
sum%=10007;
}
int sum1=1;
for(int i=0;i<b/10007;i++){
sum1*=sum;
sum1%=10007;
}
for(int i=0;i<b%10007;i++){
sum1*=a;
sum1%=10007;
}
cout<<sum1<<endl;
}
return 0;
}