#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  long long ans = (n - 1) * 2 + 3;
  if (k == 1 || k == n)
    ans += n - 1;
  else {
    int Lmx = k - 1, Rmx = n - k;
    ans += min(Lmx, Rmx) * 2 + max(Lmx, Rmx);
  }
  cout << ans << '\n';
  return 0;
}
