#include int main() { int a,b; int s; int i; while(scanf("%d %d",&a,&b)!=EOF&&a&&b) { s=1; for(i=1;i<=b;i++) { s*=a%1000; s=s%1000; } printf("%d\n",s%1000); } }