#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int x, n;
  cin >> n;
  cin >> x;
  if (x <= n / 2) {
    cout << n + 2 * x + 3 * (n - 2 * x) << endl;
  } else {
    x = n - x;
    cout << n + 2 * x + 3 * (n - 2 * x) << endl;
  }
  return 0;
}
