#include<stdio.h>
#include<stdlib.h>
#define BUFSIZE 1000000007
typedef long long ll;
int N,K;
ll rem=0;

ll Sum(ll sum,ll sum2,ll num){
    if(num == N+2)
        return 0;
    for(ll i=0;i < num;i++){
        sum += i;
        sum %= BUFSIZE;
    }
    for(ll i=N;i >= N+1-num;i--){
        sum2 += sum2;
        sum2 %= BUFSIZE;
    }
    //printf("%d %d\n",sum,sum2);
    rem += sum2 - sum + 1;
    Sum(0,0,num+1);
    return 0;
}

int main(void){
    scanf("%d",&N);
    scanf("%d",&K);
    if(N < K){
        printf("1");
        exit(0);
    }
    Sum(0,0,K);
    if(rem<0)
        printf("%lld",BUFSIZE - rem);
    else
        printf("%lld",rem % BUFSIZE);
}
