#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,m,ans=1,ans1;
inline int read(){
	int x=0,f=1;char ch=getchar();
	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;
}
inline int qpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=(ans*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return ans;
}
int main(){
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	n=read();m=read();
	if(m==n-1){
		int tot1=1,sum=0,tot2=1;
		for(int i=m;i>=1;i--){
			tot1=(tot1*i)%mod;
			tot2=(tot2*(m-i+1))%mod;
			sum=(tot1/tot2);
			ans+=sum;
		}
		printf("%d",ans*n+6*qpow(2,n-2));
	}
	else printf("1");
}