#include using ull = unsigned long long; ull modmul(ull x, ull y, ull mod){ ull ret = 0; while(y){ if(y & 1){ ret = (ret + x) % mod; } x = x * 2 % mod; y >>= 1; } return ret; } ull modpow(ull x, ull n, ull mod){ ull ret = 1; while(n){ if(n & 1){ ret = modmul(ret, x, mod); } x = modmul(x, x, mod); n >>= 1; } return ret; } constexpr ull MOD = 1000000007; int main(){ ull n, m; std::cin >> n >> m; ull a = modmul(n, n + 3, MOD); a = modmul(a, 500000004, MOD); ull b = modmul(n, n + 1, MOD); b = modmul(b, 500000004, MOD); ull ans = modpow(a, m, MOD) - modpow(b, m, MOD); std::cout << ans%1000000007 << std::endl; }