#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, x;
  cin >> n >> x;
  if (n % 2 == 1) {
    cout << 3 * n - 3 << endl;
    return 0;
  }
  if (n % 2 == 0) {
    if (x <= n / 2) {
      cout << 3 * (n - x) << endl;
    } else {
      x = n - x;
      cout << 3 * (n - x) << endl;
    }
  }
  return 0;
}
