N,M=map(int,input().split()) z,g,d=10**9+7,[1],range for i in d(1,N+1):g+=[g[-1]*i%z] print(sum((-1)**i*pow(M-i,N,z)*g[M]*pow(g[i]*g[M-i],z-2,z)for i in d(M))%z)