#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long most, least;
  long long mid = n / 2;
  if (k <= mid) {
    least = k;
    most = n - k;
  } else {
    least = n - k + 1;
    most = k - 1;
  }
  long long ans = 6 + least - 1 + (n - 2) * 3;
  cout << ans;
  return 0;
}
