#include <cstdio> int main() { int a, b, c; while(scanf("%d %d", &a, &b) && (a != 0 || b != 0)) { c = 1; for(int i = 0; i < b; ++ i) { c = c * a % 1000; } printf("%d\n", c); } return 0; }