#include<stdio.h>
int isLeap(int year);
int main() {
int a, b = 0;
long larr[33] = {0};
while(scanf("%d %d", &a, &b) != EOF) {
larr[1] = a%10007;
for (int i = 2; i <= 32; i++) {
larr[i] = larr[i-1]*larr[i-1]%10007;
}
int final = 1;
int count = 1;
while (b > 0) {
if (b&1) {
final = final * larr[count] % 10007;
}
b >>= 1;
count++;
}
printf("%ld\n", final);
}
return 0;
}