/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int a, b;
while(cin >> a >> b && (a || b)) {
int m = 1;
while(b--) {
m *= (a % 1000);
m %= 1000;
}
cout << m % 1000 << endl;
}
return 0;
}
/**/
两个公式:
1.(a * b) % c = [(a % c) * (b % c)] % c;
2.(a ^ b) % c = (a %c) ^ b % c;