#include using namespace std; long long gcd(long long a,long long b){ return b ? gcd(b,a%b) : a; } long long lcm(long long a,long long b){ return a / gcd(a,b) * b; } long long mul(long long a,long long b,const long long mod){ return b?(mul(a*2,b/2,mod)+(b&1?a:0))%mod:0; } long long bpow(long long a,long long b,const long long mod){ return (b?bpow(a*a%mod,b/2,mod)*(b&1?a:1):1)%mod; } long long inv(long long a,const long long mod){ return bpow(a,mod-2,mod); } // to overflow /*long long bpow(long long a,long long b,const long long mod){ return (b?mul(bpow(mul(a,a,mod),b/2,mod),(b&1?a:1),mod):1)%mod; }*/ class mInt{ public: static const long long mod = 1000000007; long long v; mInt():v(0){} mInt(long long v):v((v%mod+mod)%mod){} }; mInt& operator += (mInt &a,mInt b){ return a = a.v + b.v; } mInt& operator -= (mInt &a,mInt b){ return a = a.v - b.v; } mInt& operator *= (mInt &a,mInt b){ return a = a.v * b.v; } mInt& operator /= (mInt &a,mInt b){ return a = a.v * inv(b.v,mInt::mod); } mInt operator + (mInt a,mInt b){ return a += b; } mInt operator - (mInt a,mInt b){ return a -= b; } mInt operator * (mInt a,mInt b){ return a *= b; } mInt operator / (mInt a,mInt b){ return a /= b; } ostream& operator<<(ostream& os, const mInt& x){ return os << x.v; } int main(){ int A = 129402307; int B = 129402306; long long n = 0, m = 0; string a,b; cin >> a >> b; for(int i = 0 ; i < a.size() ; i++) n = (n * 10 + a[i] - '0') % A; for(int i = 0 ; i < b.size() ; i++) m = (m * 10 + b[i] - '0') % B; if( a[0] == '0' ){ cout << 0 << endl; }else{ if( m == 0 ) assert(0); cout << bpow(n,m,A) << endl; } }