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