#include<stdio.h>
int main()
{
int a,b,sum;
while(scanf("%d%d",&a,&b)!=EOF&&(a||b))
{
sum=1;
while(b--)
sum=(sum*a)%1000;
printf("%d\n",sum);
}
}
int main()
{
int a,b,sum;
while(scanf("%d%d",&a,&b)!=EOF&&(a||b))
{
sum=1;
while(b--)
sum=(sum*a)%1000;
printf("%d\n",sum);
}
}