#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7, n, m, k, a[5000005];
vector<long long> v1[5000005], vis;
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
    ;
  }
  return res;
}
int main() {
  scanf("%lld %lld", &n, &m);
  long long h1, h2, v1, v2;
  v1 = n / 2;
  v2 = n - v1;
  if (n % 2) v1++;
  long long times = m / 3;
  h1 = m - times;
  h2 = m - h1;
  if (n % 2) swap(v1, v2);
  long long ans = h1 * v1 + h2 * v2;
  ans %= mod;
  ans = power(2, ans);
  printf("%lld", ans);
}
