N,M=map(int,input().split()) z,g=10**9+7,[1] d=range for i in d(1,N+1):g.append(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)