Problem: There are well-known formulas: <image>, <image>, <image>. Also mathematicians found similar formulas for higher degrees.

Find the value of the sum <image> modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).

Input

The only line contains two integers n, k (1 ≤ n ≤ 109, 0 ≤ k ≤ 106).

Output

Print the only integer a — the remainder after dividing the value of the sum by the value 109 + 7.

Examples

Input

4 1


Output

10


Input

4 2


Output

30


Input

4 3


Output

100


Input

4 0


Output

4

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class F implements Runnable {
	public static void main (String[] args) {new Thread(null, new F(), "_cf", 1 << 28).start();}
	
	long MOD = (long)1e9+7;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int k = fs.nextInt();
		if(k == 0) {
			System.out.println(n);
			return;
		}
		
		long[] ys = new long[k+5];
		for(int i = 0; i < ys.length; i++) {
			ys[i] = power(i, k);
			if(i > 0) ys[i] = (ys[i-1] + ys[i]) % MOD;
		}
		
		if(n <= k) {
			System.out.println(ys[n]);
		}
		else {
			System.out.println(interpolate(ys, n));
		}
		
		out.close();
	}
	
	// Given k+1 (x,y) coordinates of a k-degree polynomial, allows you to query any x //%
	// O(k) interpolation given the ys of x=0,1,2,..,k //%
	long interpolate(long[] ys, long x) {
		int n = ys.length;
		long[] ifa = new long[n], b = new long[n];
		long f = 1, y = 0, a = 1;
		for (int i = 1; i < n; i++)
			f = f * i % MOD;
		ifa[n - 1] = mi(f);
		for (int i = n - 1; i >= 1; i--)
			ifa[i - 1] = ifa[i] * i % MOD;
		b[n - 1] = 1;
		for (int i = n - 1; i >= 1; i--)
			b[i - 1] = b[i] * (x - i) % MOD;
		for (int i = 0; i < n; i++) {
			long t = (a * b[i] % MOD) * ys[i] % MOD;
			t = (t * ifa[i] % MOD) * ifa[n - 1 - i] % MOD;
			y += ((n - i) & 1) == 0 ? -t : t;
			a = a * (x - i) % MOD;
		}
		return ((y % MOD) + MOD) % MOD;
	}
	// O(k^2) interpolation given any (x,y) pairs //%
	long interpolate(long[] xs, long[] ys, long x) {
		int n = ys.length;  long y = 0;
		for (int i = 0; i < n; i++) {
			long t = ys[i];
			for (int j = 0; j < n; j++)
				if (i != j) t = (t * (x - xs[j]) % MOD) * mi(xs[i] - xs[j]) % MOD;
			y += t;
		}
		return ((y % MOD) + MOD) % MOD;
	}

	long mi(long x) {
		return power(x, MOD - 2);
	}
	
	long power(long base, long expo) {
		base %= MOD;
		long x = base;
		long res = 1;
		while(expo > 0) {
			if((expo & 1L) > 0) {
				res = res * x % MOD;
			}
			x = x * x % MOD;
			expo /= 2;
		}
		return res;
	}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

	
}