#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long N, X;
  cin >> N >> X;
  long long res = 0LL;
  if (N % 2LL != 0LL) {
    res = (N - 1LL) * 3LL;
  } else {
    if (X > N / 2LL) X = N - X;
    res = (N - 1LL) * 3LL - (X - 1LL) * 3LL;
  }
  cout << res << endl;
  return 0;
}
