open System

let [|n; m|] = Console.ReadLine().Split(' ') |> Array.map int

let P = 1000000007L
let mutable fac : int64 array = Array.zeroCreate(m+1)
let mutable inv : int64 array = Array.zeroCreate(m+1)
let mutable facinv : int64 array = Array.zeroCreate(m+1)
fac.[0] <- 1L
inv.[0] <- 1L
facinv.[0] <- 1L
fac.[1] <- 1L
inv.[1] <- 1L
facinv.[1] <- 1L
for i = 2 to m do
    fac.[i] <- fac.[i-1]*int64(i)%P
    inv.[i] <- (-(((P/int64(i))*inv.[int(P)%i])%P)+P)%P
    facinv.[i] <- facinv.[i-1]*inv.[i]%P
let C n m = fac.[n]*facinv.[m]%P*facinv.[n-m]%P
let mutable Ans = 0L
for i = 0 to n do
    Ans <- (Ans+C(n)(i)*C(m-i)(n-i)%P*fac.[n-i]%P*int64(1-(i&&&1)*2)+P)%P
Console.Write(Ans*C(m)(n)%P*fac.[n]%P)