import java.io.BufferedReader

fun main() {
    val mod = 1_000_000_007L
    fun modPow(n: Long, k: Int, m: Long = mod): Long {
        if (k == 0) {
            return 1L
        }
        var half = modPow(n, k shr 1, m)
        half *= half
        if (k and 1 == 1) {
            half %= m
            half *= n
        }
        return half % m
    }

    val br = System.`in`.bufferedReader()
    val length = br.readInt()
    val maxNum = br.readInt()

    val factorial = LongArray(maxNum + 1) { 1L }
    val invFactorial = LongArray(maxNum + 1) { 1L }
    for (x in 1..maxNum) {
        factorial[x] = (factorial[x - 1] * x) % mod
        invFactorial[x] = modPow(factorial[x], (mod - 2).toInt())
    }
    fun choose(n: Int, k: Int): Long {
        val ret = (factorial[n] * invFactorial[k]) % mod
        return (ret * invFactorial[n - k]) % mod
    }

    var tot = 0L
    var sign = 1
    for (x in 0..length) {
        var part = choose(length, x) * choose(maxNum - x, length - x)
        part %= mod
        part *= factorial[length - x]
        part %= mod

        tot += sign * part
        tot += mod
        tot %= mod
        sign *= -1
    }
    tot *= factorial[maxNum]
    tot %= mod
    tot *= invFactorial[maxNum - length]
    tot %= mod
    print(tot)
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}