#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0,w=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+ch-'0';ch=getchar();}
	return s*w;
}
int n,m;
long long mod=1e9+7;
long long po[500005];
int main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	n=read();m=read();
	po[0]=1;
	for(int i=1;i<=500000;++i){
		po[i]=(po[i-1]*2)%mod;
	}
	long long ans=1;
	if(n==1)ans=1;
	if(m==n-1){
		for(int i=1;i<=m;++i){
			ans=(ans+n*po[i])%mod;
		}
	}
	else if(m==n){
		for(int i=1;i=m;++i){
			ans=(ans+n*po[i])%mod;
		}
		ans=(ans+po[m]-1-n)%mod;
	}
	printf("%lld",ans);
	fclose(stdin);fclose(stdout);
	return 0;
}
