#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int MAXN = 2e5 + 1;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
long long n, x, y;
int main() {
  faster();
  cin >> n >> x;
  if (n % 2 == 0)
    cout << 3ll * (n - 1) - (max(x, n - x) - 1) * 3;
  else
    cout << 3ll * (n - 1);
  return 0;
}
