http://noi.openjudge.cn/math/7833/
"""
小学奥数 7833 幂的末尾
http://noi.openjudge.cn/math/7833/
"""
a,b=map(int,input().split())
p=1000
ans=1
while b:
if b&1:
ans=a*ans%p
a=a*a%p
b>>=1
print("%03d" %ans)