import java.lang.Integer.min
import java.util.*
import kotlin.math.max

fun readInt(): Int = readLine()!!.toInt()
fun readInts(): List<Int> = readLine()!!.split(" ").map { it.toInt() }

fun parseInt(): Int {
    var digit = System.`in`.read()
    while(digit <= 32) {
        digit = System.`in`.read()
    }

    val negative = digit == '-'.toInt()
    if (negative) {
        digit = System.`in`.read()
    }
    var res = 0
    while (digit in '0'.toInt()..'9'.toInt()) {
        res *= 10
        res += digit - '0'.toInt()
        digit = System.`in`.read()
    }
    return if (negative) -res else res
}

fun gcd(x : Int, y : Int) : Int {
    var a = x
    var b = y
    var r = 0
    while(b > 0) {
        r = a % b
        a = b
        b = r
    }
    return a
}

val MOD : Int = 1000000007

fun pw(base : Int, exp : Int) : Int {
    var b = base.toLong()
    var e = exp
    var res = 1L
    while(e > 0) {
        if ((e and 1) != 0) {
            res = (1L * res * b) % MOD
        }
        b = (1L * b * b) % MOD
        e = e shr 1
    }

    return res.toInt()
}

fun main() {
//    val t = readLine()!!.toInt()
    val t = 1

    for(testNumber in 1..t) {
        val (n, m) = readInts()
        val sz = max(m, n) + 1
        val f = IntArray(sz)
        f[0] = 1
        for(i in 1 until sz) f[i] = ((1L * f[i - 1] * i) % MOD).toInt()

        val inv = IntArray(sz)
        inv[sz - 1] = pw(f[sz - 1], MOD - 2)
        for(i in sz - 2 downTo 0) inv[i] = ((1L * inv[i + 1] * (i + 1)) % MOD).toInt()

        fun comb(n : Int, k : Int) : Int {
            return ((1L * f[n] * inv[k]) % MOD * inv[n - k] % MOD).toInt()
        }

        fun aranj(n : Int, k : Int) : Int {
            return (1L * f[n] * inv[n - k] % MOD).toInt()
        }

        var ans = 0
        for(nrEq in 0..n) {
            val term = 1L * comb(n, nrEq) * aranj(m - nrEq, n - nrEq) % MOD
            if(nrEq % 2 == 0) {
                ans += term.toInt()
                if(ans >= MOD) ans -= MOD
            } else {
                ans -= term.toInt()
                if(ans < 0) ans += MOD
            }
        }

        println(1L * ans * aranj(m, n) % MOD)
    }
}