#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, p;
  cin >> n >> p;
  int ans = 0;
  ans += 2;
  int mn = min(n - p, p - 1);
  int mx = max(n - p, p - 1);
  ans += 4 * mn + 3 * mx;
  ans++;
  cout << ans;
  return 0;
}
