#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;
int main(int argc, char *argv[]) {
  long long n, x;
  cin >> n >> x;
  long long ans;
  if (n % 2) {
    if (x > n / 2)
      ans = x + 4 * (n - x);
    else if (x < n / 2 + 1)
      ans = 3 * x + (n - x) + 3 * (n - 2 * x);
    else
      ans = 3 * x;
  } else {
    if (x > n / 2)
      ans = x + 4 * (n - x);
    else if (x < n / 2)
      ans = 3 * x + (n - x) + 3 * (n - 2 * x);
    else
      ans = 3 * x;
  }
  cout << ans << endl;
  return 0;
}
