using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ modComb.Init((int)2e6); long ans = 0; long mod = (long)1e9+7; int sig = 1; for(long i=M;i>=1;i--){ long val = modComb.PowMod(i,N); val *= modComb.nCrMod(M,i); if(sig == 1) ans += val; if(sig == -1) ans += (mod - val); if(ans >= mod) ans -= mod; sig *= -1; } Console.WriteLine(ans); } long N,M; public Sol(){ var d = rla(); N = d[0]; M = d[1]; } static String rs(){return Console.ReadLine();} static int ri(){return int.Parse(Console.ReadLine());} static long rl(){return long.Parse(Console.ReadLine());} static double rd(){return double.Parse(Console.ReadLine());} static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);} static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));} static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));} static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));} } class modComb{ public static long mod=(long)(1e9+7); public static long nCrMod(long n,long r){ if(n0){ if((k&1)==1){ret*=x;ret%=mod;} x*=x;x%=mod; k>>=1; } return ret; } public static long InvMod(long n){ //(mod-2)乗を返す // modが素数の時だけ!!!! return PowMod(n,mod-2); } }