#include<stdio.h>
int main()
{
int a,b,i,ans;
while(scanf("%d%d",&a,&b)!=EOF,(a+b))
{
ans=1;
a=a%1000;
while(b)
{
if(b%2==1) ans=(ans*a)%1000;
b=b/2;
a=(a*a)%1000;
}
printf("%d\n",ans);
}
return 0;
}
int main()
{
int a,b,i,ans;
while(scanf("%d%d",&a,&b)!=EOF,(a+b))
{
ans=1;
a=a%1000;
while(b)
{
if(b%2==1) ans=(ans*a)%1000;
b=b/2;
a=(a*a)%1000;
}
printf("%d\n",ans);
}
return 0;
}