#include<bits/stdc++.h>

using namespace std;

long long cs[1000005];

int main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	
	int n,m;
	int i,j;
	
	cin >> n >> m;
	const int Mod=1000000007;
	
	if (m==n-1)
	{
		long long s=0;
		long long sm=1;
		long long ss=1;
		for (i=1;i<=m;i++)
		    cs[i]=sm,sm*=2;
		s=n*sm%Mod;
		for (i=1;i<=n-1;i++)
		    s=(s+i*cs[i]%Mod)%Mod;
		    
		cout << s;
	}
	
	return 0;
}
