#include <bits/stdc++.h>
using namespace std;

template <long long mod>
class Mod
{
    long long value;
    void set_value(const long long x)
    {
        this->value = x % mod;
    }

public:
    Mod()
    {
        set_value(0ll);
    }

    template <typename T>
    Mod(T x = 0)
    {
        set_value((long long)x);
    }

    friend istream &operator>>(istream &is, Mod &x)
    {
        long long tmp;
        is >> tmp;
        x.set_value(tmp);
        return is;
    }

    friend ostream &operator<<(ostream &os, const Mod &x)
    {
        os << x.value;
        return os;
    }

    operator long long() const
    {
        return this->value;
    }

    template <typename T>
    bool operator<(const T x)
    {
        return this->value < (long long)x;
    }

    template <typename T>
    bool operator<=(const T x)
    {
        return this->value <= (long long)x;
    }

    template <typename T>
    bool operator>(const T x)
    {
        return this->value > (long long)x;
    }

    template <typename T>
    bool operator>=(const T x)
    {
        return this->value >= (long long)x;
    }

    template <typename T>
    bool operator==(const T x)
    {
        return this->value == (long long)x;
    }

    template <typename T>
    Mod &operator=(const T x)
    {
        set_value((long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator&=(const T x)
    {
        set_value(this->value & (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator|=(const T x)
    {
        set_value(this->value | (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator^=(const T x)
    {
        set_value(this->value ^ (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator<<=(const T x)
    {
        set_value(this->value << (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator>>=(const T x)
    {
        set_value(this->value >> (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator+=(const T x)
    {
        set_value(this->value + (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator-=(const T x)
    {
        set_value(this->value - (long long)x + mod);
        return *this;
    }

    template <typename T>
    Mod &operator*=(const T x)
    {
        set_value(this->value * (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator/=(const T x)
    {
        long long a = (long long)x;
        long long b = mod;
        long long u = 1;
        long long v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= mod;
        if (u < 0)
            u += mod;
        *this *= Mod(u);
        return *this;
    }

    template <typename T>
    Mod operator&(const T x) const
    {
        return Mod(*this) &= x;
    }

    template <typename T>
    Mod operator|(const T x) const
    {
        return Mod(*this) |= x;
    }

    template <typename T>
    Mod operator^(const T x) const
    {
        return Mod(*this) ^= x;
    }

    template <typename T>
    Mod operator<<(const T x) const
    {
        return Mod(*this) <<= x;
    }

    template <typename T>
    Mod operator>>(const T x) const
    {
        return Mod(*this) >>= x;
    }

    template <typename T>
    Mod operator+(const T x) const
    {
        return Mod(*this) += x;
    }

    template <typename T>
    Mod operator-(const T x) const
    {
        return Mod(*this) -= x;
    }

    template <typename T>
    Mod operator*(const T x) const
    {
        return Mod(*this) *= x;
    }

    template <typename T>
    Mod operator/(const T x) const
    {
        return Mod(*this) /= x;
    }

    Mod &operator++()
    {
        *this += 1;
        return *this;
    }

    Mod &operator--()
    {
        this->set_value(--this->value);
        return *this;
    }

    Mod operator++(int)
    {
        Mod ret(*this);
        ++*this;
        return ret;
    }

    Mod operator--(int)
    {
        Mod ret(*this);
        --*this;
        return ret;
    }
};

template <typename T>
class Combination
{
    const std::vector<T> fact;
    const std::vector<T> ifact;
    const size_t size;

    vector<T> calc_fact(const size_t n)
    {
        std::vector<T> ret(n + 1);
        ret[0] = (T)1;
        for (size_t i = 1; i <= n; i++)
        {
            ret[i] = ret[i - 1] * (T)i;
        }
        return ret;
    }

    vector<T> calc_ifact(const size_t n)
    {
        std::vector<T> ret = calc_fact(n);
        ret[n] = (T)1 / ret[n];
        for (size_t i = n; i > 0; i--)
        {
            ret[i - 1] = ret[i] * (T)i;
        }
        return ret;
    }

public:
    Combination(const size_t n) : fact(calc_fact(n)), ifact(calc_ifact(n)), size(n)
    {
    }

    T operator()(const size_t n, const size_t k) const
    {
        if (k < 0 || k > n || n > this->size)
        {
            return (T)0;
        }
        return this->fact[n] * this->ifact[k] * this->ifact[n - k];
    }

    T operator[](const size_t index) const
    {
        return this->fact[index];
    }
};

template <typename T, typename U>
T power(const T x, const U y)
{
    T ret = 1;
    T xx = x;
    U yy = y;
    while (yy > 0)
    {
        if ((yy & 1) > 0)
        {
            ret *= xx;
        }
        xx *= xx;
        yy /= 2;
    }
    return ret;
}

int main()
{
    constexpr size_t MOD = 1e9 + 7;
    size_t N, M;
    cin >> N >> M;

    vector<Mod<MOD>> dp(M, 0);
    Mod<MOD> ans = 0;
    Combination<Mod<MOD>> com(M + 5);

    for (size_t i = 0; i <= N; i++)
    {
        if (i % 2 == 0)
        {
            ans += com(N, i) * com[M - i] / com[M - N];
        }
        else
        {
            ans -= com(N, i) * com[M - i] / com[M - N];
        }
    }
    cout << com[M] / com[M - N] * ans << endl;
}


Measured memory_bytes: 14856