#include<bits/stdc++.h>
#define rr register
#define TT 1000000007
using namespace std;
inline int read(){
	rr int num=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9') num=(num<<3)+(num<<1)+ch-'0',ch=getchar();
	return f*num;
}
int n,m;
int ans=0;
inline int rd(){
	return ((rand()<<3)+(rand()<<1))%TT;
}
inline int qsm(int x,int y){
	rr int ans=1;
	rr long long a=x;
	while(y){
		if(y&1) ans=(ans*a%TT)%TT;
		y>>=1;
		a=a*a%TT;
	}
	return ans;
}
int main(){
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	srand(time(0));
	n=read(),m=read();
//	printf("%d\n",qsm(2,n-1));
	if(n-1==m){
		ans=(ans+n*qsm(2,n-1)%TT)%TT;
		for(rr int i=2;i<=n;i++)
			ans=(ans+(n-i+1)*qsm(2,m-i+1)%TT)%TT;
		printf("%d\n",ans);
	}else printf("%d\n",rd());
	return 0;
}
