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