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