#include <bits/stdc++.h>
using namespace std;
void FAST() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
bool same_floats(double a, double b) {
  if (abs(a - b) < 1e-9)
    return true;
  else
    return false;
}
long long powM(long long x, long long y, long long m) {
  long long ans = 1, r = 1;
  x %= m;
  while (r > 0 && r <= y) {
    if (r & y) {
      ans *= x;
      ans %= m;
    }
    r <<= 1;
    x *= x;
    x %= m;
  }
  return ans;
}
map<long long, long long> factorize(long long n) {
  map<long long, long long> ans;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ans[i]++;
      n /= i;
    }
  }
  if (n > 1) {
    ans[n]++;
    n = 1;
  }
  return ans;
}
int main() {
  FAST();
  int n, k;
  cin >> n >> k;
  int a[n], step;
  for (long long i = 0; i < n; i++) {
    a[i] = 1;
  }
  k--;
  if (k <= n - 1 - k)
    step = k;
  else
    step = n - 1 - k;
  cout << step + 3 * n;
  return 0;
}
