#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
const int mods = 1e9+7;
int n, m;
// This is so hard that what i can do is to 
// finish some special checkpoint
// for example a chain or a circle
int getpow(int base, int power){
	if (power==0) return 1;
	if (base==2){
		int res=1;
		while (power>0){
			if (power>=15){
				res *= (1<<15) % mods;
				res %= mods;
				power-=15;
			} else {
				res *= (1<<power) % mods;
				res %= mods;
				power = 0;
			}
		}
		return res%mods;
	}
	int res = 1;
	for (int i=0;i<power;i++){
		res *= base;
		res %= mods;
	}
	return res%mods;
}
int csmem[11000][11000];
int choosing(int from, int num){
	if (from<=1 || num==0) return 1;
	if (from==num) return 1;
	if (num*2>from) num=from-num;
	if (num==1) return from%mods;
	if (num==from-1) return from%mods;
	if (from<11000){
		if (csmem[from][num]==0)
		csmem[from][num]=(choosing(from-1, num-1)+choosing(from-1, num))%mods;
		return csmem[from][num];
	}
	return (choosing(from-1, num-1)+choosing(from-1, num))%mods;
}
int main(){
	freopen("barrack.in", "r", stdin);
	freopen("barrack.out","w", stdout);
	cin>>n>>m;
	// neednt input edges at all
	int ans = 0;
	if (m==n-1){
		// map is a chain;
		
		// single spot;
		ans += (n%mods)*(getpow(2, m)%mods)%mods;
		ans %= mods;
		// multiple spots;
		for (int point=2;point<=n;point++){
			for (int le=0; le<n; le++){
				for (int re=le+point-1; re<n; re++){
					if (re-le+1<point) continue;
					ans += (choosing(re-le-1,point-2)*((getpow(2, le)*getpow(2, n-re-1))%mods))%mods;
					ans %= mods;
				}
			}
		}
	} else if (n==m){
		// map is a circle maybe;
		// put any amount of construction;
		// put any amount of army;
		for (int i=1;i<=n;i++){
			ans += choosing(n,i)*getpow(2, m)%mods;
			ans %= mods;
		}
	} else {
		// random!
		srand(time(NULL));
		ans += rand() % mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
		ans += rand() % mods;
		ans %= mods;
	}
	cout<<ans<<endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}