LARGE = 10 ** 9 + 7


def solve(n, k):
    # singular cases
    if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
    pow_mod = [1] * (n + 1)
    for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
    pow_mod_inv = [1] * (n + 1)
    pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
    for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

    res = 0
    for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
    return res


def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res)


def test():
    assert solve(3, 2) == 10
    assert solve(200000, 1000000000) == 607923868
    assert solve(15, 6) == 22583772


if __name__ == "__main__":
    test()
    main() LARGE = 10 ** 9 + 7 LARGE 10 ** 9 + 7 10 ** 9 10 9 7 def solve(n, k):
    # singular cases
    if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
    pow_mod = [1] * (n + 1)
    for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
    pow_mod_inv = [1] * (n + 1)
    pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
    for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

    res = 0
    for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
    return res solve if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
     k == 0 k 0 return 1 1 elif k == 1:
        return n * (n - 1)

    # pow
     k == 1 k 1 return n * (n - 1) n * (n - 1) n n - 1 n 1 pow_mod = [1] * (n + 1) pow_mod [1] * (n + 1) [1] 1 n + 1 n 1 for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
     i range(n) range n pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE pow_mod[i + 1] pow_mod i + 1 i 1 pow_mod[i] * (i + 1) % LARGE pow_mod[i] * (i + 1) pow_mod[i] pow_mod i i + 1 i 1 LARGE pow_mod_inv = [1] * (n + 1) pow_mod_inv [1] * (n + 1) [1] 1 n + 1 n 1 pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE) pow_mod_inv[-1] pow_mod_inv -1 pow(pow_mod[-1], LARGE - 2, LARGE) pow pow_mod[-1] pow_mod -1 LARGE - 2 LARGE 2 LARGE for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

     i range(n - 1, 0, -1) range n - 1 n 1 0 -1 pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE pow_mod_inv[i] pow_mod_inv i pow_mod_inv[i + 1] * (i + 1) % LARGE pow_mod_inv[i + 1] * (i + 1) pow_mod_inv[i + 1] pow_mod_inv i + 1 i 1 i + 1 i 1 LARGE res = 0 res 0 for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
     i range(min(k, n - 1) + 1) range min(k, n - 1) + 1 min(k, n - 1) min k n - 1 n 1 1 pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE pick_zeros pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] pow_mod[n] * pow_mod_inv[i] pow_mod[n] pow_mod n pow_mod_inv[i] pow_mod_inv i pow_mod_inv[n - i] pow_mod_inv n - i n i LARGE assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE assign_ones pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] pow_mod[n - 1] * pow_mod_inv[i] pow_mod[n - 1] pow_mod n - 1 n 1 pow_mod_inv[i] pow_mod_inv i pow_mod_inv[n - 1 - i] pow_mod_inv n - 1 - i n - 1 n 1 i LARGE res += pick_zeros * assign_ones res pick_zeros * assign_ones pick_zeros assign_ones res %= LARGE res LARGE return res res n n k k def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res) main n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k res = solve(n, k) res solve(n, k) solve n k print(res) print res def test():
    assert solve(3, 2) == 10
    assert solve(200000, 1000000000) == 607923868
    assert solve(15, 6) == 22583772 test assert solve(3, 2) == 10 solve(3, 2) == 10 solve(3, 2) solve 3 2 10 assert solve(200000, 1000000000) == 607923868 solve(200000, 1000000000) == 607923868 solve(200000, 1000000000) solve 200000 1000000000 607923868 assert solve(15, 6) == 22583772 solve(15, 6) == 22583772 solve(15, 6) solve 15 6 22583772 if __name__ == "__main__":
    test()
    main() __name__ == "__main__" __name__ "__main__" test() test main() main LARGE = 10 ** 9 + 7 10 ** 9 + 7 LARGE def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res) def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res) main def test():
    assert solve(3, 2) == 10
    assert solve(200000, 1000000000) == 607923868
    assert solve(15, 6) == 22583772 def test():
    assert solve(3, 2) == 10
    assert solve(200000, 1000000000) == 607923868
    assert solve(15, 6) == 22583772 test def solve(n, k):
    # singular cases
    if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
    pow_mod = [1] * (n + 1)
    for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
    pow_mod_inv = [1] * (n + 1)
    pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
    for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

    res = 0
    for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
    return res def solve(n, k):
    # singular cases
    if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
    pow_mod = [1] * (n + 1)
    for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
    pow_mod_inv = [1] * (n + 1)
    pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
    for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

    res = 0
    for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
    return res solve
LARGE = 10 ** 9 + 7


def solve(n, k):
    # singular cases
    if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
    pow_mod = [1] * (n + 1)
    for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
    pow_mod_inv = [1] * (n + 1)
    pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
    for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

    res = 0
    for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
    return res


def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res)


def test():
    assert solve(3, 2) == 10
    assert solve(200000, 1000000000) == 607923868
    assert solve(15, 6) == 22583772


if __name__ == "__main__":
    test()
    main()
