#include <bits/stdc++.h>
using namespace std;
long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
long long power(long long a, long long b) {
  long long res = 1LL;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    b /= 2;
    a = mul(a, a);
  }
  return res % 1000000007;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long a = min(k - 1, n - k);
  long long temp = a;
  temp += 2;
  temp += (3 * (n - k));
  long long b = k - 1;
  temp += ((3 * b));
  temp += 1;
  cout << temp << endl;
  return 0;
}
