#include <iostream>
using namespace std;
#define int long long
int ltnp(int a, int b)
{
int kq=1,d,c;
while (b>0)
{
c=1; d=a;
while (c<=b/2) { c=c*2; d=(d*d)%10000; }
b-=c; kq=(kq*d)%10000;
}
return kq;
}
signed main()
{
int a,b; cin>>a>>b; cout<<ltnp(a,b);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGludCBsb25nIGxvbmcKaW50IGx0bnAoaW50IGEsIGludCBiKQp7CglpbnQga3E9MSxkLGM7Cgl3aGlsZSAoYj4wKQoJewoJCWM9MTsgZD1hOwoJCXdoaWxlIChjPD1iLzIpIHsgYz1jKjI7IGQ9KGQqZCklMTAwMDA7IH0KCQliLT1jOyBrcT0oa3EqZCklMTAwMDA7Cgl9CglyZXR1cm4ga3E7Cn0Kc2lnbmVkIG1haW4oKSAKewoJaW50IGEsYjsgY2luPj5hPj5iOyBjb3V0PDxsdG5wKGEsYik7CglyZXR1cm4gMDsKfQ==