#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  cin >> N >> X;
  int ret = 0;
  if (N - 2 * X > 0) {
    ret = 3 * (N - X) + 6 * (N - 2 * X);
  } else {
    ret = X + 6 * (N - X);
  }
  cout << ret << endl;
  return 0;
}
