#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct mat {
  long long a[3][3];
} yi;
mat mul(mat x, mat y) {
  int i, j, k;
  long long mmm;
  mat r;
  for (i = 1; i <= 2; i++) {
    for (j = 1; j <= 2; j++) {
      r.a[i][j] = 0;
      for (k = 1; k <= 2; k++) {
        r.a[i][j] = (r.a[i][j] + (x.a[i][k] * y.a[k][j]) % MOD) % MOD;
      }
    }
  }
  return r;
}
mat pw(mat x, long long b) {
  mat r = yi, base = x;
  r.a[1][2] = 0;
  r.a[2][1] = 0;
  while (b) {
    if (b & 1) r = mul(r, base);
    base = mul(base, base);
    b >>= 1;
  }
  return r;
}
int main() {
  int i;
  mat jiabei;
  jiabei.a[1][1] = 2;
  jiabei.a[1][2] = 0;
  jiabei.a[2][1] = -1;
  jiabei.a[2][2] = 1;
  yi.a[1][1] = yi.a[1][2] = yi.a[2][1] = yi.a[2][2] = 1;
  long long a, b;
  cin >> a >> b;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }
  a %= MOD;
  a = (a + a) % MOD;
  mat p = yi;
  p.a[1][1] = a;
  jiabei = pw(jiabei, b);
  p = mul(p, jiabei);
  if (p.a[1][1] < 0) p.a[1][1] += MOD;
  cout << p.a[1][1] << endl;
  return 0;
}
