#include using i64 = long long; constexpr int P = 1e9 + 7; template T expow(T a, T b) { T res = 1 % P; for (; b; b >>= 1) { if (b & 1) res = 1ll * res * a % P; a = 1ll * a * a % P; } return res; } template T read() { T sum = 0, fl = 1; int ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') fl = -1; } for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0'; return sum * fl; } template void write(T x) { if (x < 0) { x = -x; putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + '0'); } /* with unlocked: only available on Linux platform */ // template T read() { // T sum = 0, fl = 1; // int ch = getchar_unlocked(); // for (; !isdigit(ch); ch = getchar_unlocked()) { if (ch == '-') fl = -1; } // for (; isdigit(ch); ch = getchar_unlocked()) sum = sum * 10 + ch - '0'; // return sum * fl; // } // template void write(T x) { // if (x < 0) { x = -x; putchar_unlocked('-'); } // if (x > 9) write(x / 10); // putchar_unlocked(x % 10 + '0'); // } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n = read(), k = read(); i64 res = n * (expow(n, k) + P - expow(n + 1, k)) % P; write(res); return 0; }