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