#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9+7;
long long n,m;

long long ksm(long long a,long long b)
{
	long long c = 1;
	while ( b )
	{
		if ( b&1 ) c = c*a%mod;
		a = a*a%mod;
		b >>= 1;
	}
	return c;
}
int main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	scanf("%lld%lld",&n,&m);
	
	if ( n == m )
	{
		long long ans = ksm(2,n)*(ksm(2,n)-1)%mod;
		printf("%lld",ans);
	}
	else
	{
		long long ans = (n+ksm(2,n)-1)%mod;
		printf("%lld",ans);
	}
	
	
	return 0;
}