val mod = (1e9 + 7).toInt()

fun main() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    val fact = Array(m + 1) { 1L }
    for (i in 1..m) fact[i] = fact[i - 1] mul i.toLong()

    val invFact = Array(m + 1) { i -> inv(fact[i]) }

    val C = Array(n + 1) { k -> fact[n] mul invFact[k] mul invFact[n - k] }
    val Pm = Array(n + 1) { k -> fact[m] mul invFact[m - k] }
    val P2 = Array(n + 1) { k -> fact[m - k] mul invFact[m - k - (n - k)] }

    var res = 0L
    for (k in 0..n) {
        val x = C[k] mul Pm[k] mul P2[k] mul P2[k]
        if (k % 2 == 0) res = (res + x) % mod
        else res = (res + mod - x) % mod
    }
    println(res)
}

private fun inv(x: Long): Long {
    return pow(x, mod - 2)
}

private fun pow(a: Long, x: Int): Long {
    var a = a
    var x = x
    var res = 1L
    while (x > 0) {
        if (x % 2 == 1) res = res mul a
        a = a mul a
        x /= 2
    }
    return res
}

private infix fun Long.mul(other: Long): Long = (this * other) % mod
