#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>

const long long mod = 1e9+7;

long long bin(long long n, long long p)
{
  long long r =1;
  for(int i = p+1; i <= n; i++)
  {
    r *= i;
  	r %= mod;
  }
  
  for(int i = 1; i <= n-p; i++)
    r /= i;
  
  return r;
}

long long fastPow(long long base, long long exp)
{
  long long ans = 1;
  while(exp)
  {
    if(exp & 1)
      ans *= base;
    
    ans %= mod;
    exp = exp >> 1;
    base = (base*base)%mod;
  }
  
  return ans;
}

int main()
{
  long long n,k;
  cin >> n >> k;
  long long  total = fastPow(2,n+1);
  total -= max(n-2,0)*max(n-2,0);
  long long r = bin(n+1,k);
  r -= max(min(k,n)-2,0)*max(n-2,0);
  cout << total - r << enld;
}
