#include <bits/stdc++.h>

#define ll long long
#define N 5005

using namespace std;

int n,m;
ll ans=0;

ll p2_dat[N]={0};
ll c_dat[N][N/2]={0};

ll read()
{
    ll x=0;
	int f=1;
    char ch=0;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+(ch-'0');
        ch=getchar();
    }
    return x*f;
}

ll JC(int st,int ed)	//st>end
{
	int i;
	ll res=1;
	for(i=st;i>=ed;i--)
	{
		res*=i;
	}
	return res;
}

ll C(int xx,int xy)
{
	int mt=xx,nt;
	if(xx<2*xy)
	{
		nt=xx-xy;
	}
	else
	{
		nt=xy;
	}
	if(c_dat[mt][nt]!=0)
		return c_dat[mt][nt];
	ll fenzi=JC(mt,mt-nt+1);
	ll fenmu=JC(nt,1);
	ll res=fenzi/fenmu;
	c_dat[mt][nt]=fenzi/fenmu;
	return  res;
}

ll p2(int x)
{
	if(p2_dat[x]!=0)
		return p2_dat[x];
	int i;
	ll res=1;
	for(i=1;i<=x;i++)
		res*=2;
	p2_dat[x]=res;
	return res;
}


//ans
int main()
{
    freopen("barrack.in","r",stdin);
    freopen("barrack.out","w",stdout);
    n=read();
    m=read();
    int i,j,k,l;
    if(m==n-1)
    {
    	//if(n==2)	printf("5\n");
    	//else if(n==3)	printf("18\n");
    	//else
    	{
    		for(i=n;i>=1;i--)
		   	{
		   		ans+=i*p2(i-1);
//		   		if(ans>=1000000007)
//		   			ans%=1000000007;
			}
			for(i=3;i<=n;i++)
			{
				for(j=i;j<=n;j++)
				{
					ans+=(n-j+1)*C(j-2,i-2)*p2(n-j);
//					if(ans>=1000000007)
//		   				ans%=1000000007;
				}
			}
		}
		
	}
	else
		{
			srand(time(NULL));
			ans=rand()%20000+500;
		}
	ans%=1000000007;
    printf("%lld\n",ans);
    return 0;
}