// Written By NewbieChd
#include <cstdio>
using namespace std;
const int mod = 1e9 + 7;
inline void swap(int& x, int& y) { x ^= y, y ^= x, x ^= y; }
int main() {
int n, m, i, ans;
scanf("%d%d", &n, &m);
if (n > m)
swap(n, m);
if (n == 1) {
ans = 2;
for (i = 1; i < m; ++i)
ans = (ans << 1) % mod;
}
if (n == 2) {
ans = 12;
for (i = 2; i < m; ++i)
ans = 3ll * ans % mod;
}
if (n == 3) {
ans = 112;
for (i = 3; i < m; ++i)
ans = 3ll * ans % mod;
}
if (n == 4) {
if (m == 4)
ans = 912;
else {
ans = 2688;
for (i = 5; i < m; ++i)
ans = 3ll * ans % mod;
}
}
if (n == 5) {
if (m == 5)
ans = 7136;
else {
ans = 21312;
for (i = 6; i < m; ++i)
ans = 3ll * ans % mod;
}
}
if (n == 6) {
if (m == 6)
ans = 56768;
else {
ans = 170112;
for (i = 7; i < m; ++i)
ans = 3ll * ans % mod;
}
}
if (n == 7) {
if (m == 7)
ans = 453504;
else {
ans = 1360128;
for (i = 8; i < m; ++i)
ans = 3ll * ans % mod;
}
}
if (n == 8) {
if (m == 8)
ans = 3626752;
else {
ans = 10879488;
for (i = 9; i < m; ++i)
ans = 3ll * ans % mod;
}
}
printf("%d\n", ans);
return 0;
}