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