#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE

using M = Mint<int>;
const int MAX = 5050;
M dp[MAX][MAX];
int used[MAX][MAX]={};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,m;
  cin>>n>>m;
  vector<M> po(n+m+1,1);
  for(int i=0;i<n+m;i++) po[i+1]=po[i]*M(2);

  MFP([&](auto dfs,int h,int w)->M{
    // cout<<h<<' '<<w<<endl;
    M &res=dp[h][w];
    if(used[h][w]) return res;
    used[h][w]=1;

    assert(h>=0 and w>=0);
    if(h==0 or w==0) return res=M(1);
    if(w==1) return res=po[h];
    if(h==1) return res=po[w];

    res=M(0);

    //  (j)  (w-j)
    // 0...0/1...1
    for(int j=0;j<=w;j++)
      res+=dfs(h-1,j)*dfs(h-1,w-j);

    //  (j) (1)(?)(1)(k)
    // 0...0/1?????0(1*)
    /*
    for(int j=0;j+1<w;j++)
      for(int k=0;j+1+k<w;k++)
        res+=dfs(h-1,j+1+k)*po[w-(j+1+k+1)];
    */

    // j+k -> j
    for(int j=0;j+1<w;j++)
      res+=dfs(h-1,j+1)*po[w-(j+1+1)]*M(w-(j+1));

    return res;
  })(n,m);

  cout<<dp[n][m]<<newl;
  return 0;
}
