fun main() {
    val mod = 1000000007L

    fun modPow(x: Long, n: Int, m: Long): Long {
        if (n == 0) return 1 % m
        var u = modPow(x, n / 2, m)
        u = (u * u) % m
        if (n % 2 == 1) u = (u * x) % m
        return u
    }

    fun modInverse(x: Long, m: Long): Long {
        return modPow(x, m.toInt() - 2, m)
    }

    val (n, m) = readInts().map { it.toLong() }

    val mPnArray = LongArray(n.toInt())
    for (j in (m - n + 1)..m) {
        val index = (j - (m - n + 1)).toInt()
        mPnArray[index] = j
        if (index > 0) mPnArray[index] = (mPnArray[index] * mPnArray[index - 1]) % mod
    }

    val factorials = LongArray(n.toInt() + 1)
    val factorialModInverses = LongArray(n.toInt() + 1)
    for (i in 0..n) {
        val index = i.toInt()
        if (index == 0) factorials[index] = 1
        else factorials[index] = (i * factorials[index - 1]) % mod
        factorialModInverses[index] = modInverse(factorials[index], mod)
    }

    val nChooseR = factorials.mapIndexed { index, _ ->
        val nr = factorialModInverses[n.toInt() - index]
        val r = factorialModInverses[index]
        (((factorials[n.toInt()] * nr) % mod) * r) % mod
    }

    fun derangements(): Long {
        val mPn = mPnArray.last()
        val minusTerm = (1..n).map { r ->
            val sign = if (r % 2 == 1L) 1 else -1
            val p = if (n - r - 1 < 0) 1 else mPnArray[(n - r - 1).toInt()]
            val choice = nChooseR[r.toInt()]
            (mod + sign * ((p * choice) % mod)) % mod
        }.reduce { acc, minus -> (acc + minus) % mod }
        return ((mod + mPn) - minusTerm) % mod
    }

    val mPn = mPnArray.last()
    println((mPn * derangements()) % mod)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
