#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, inf = 1e18, mod = 1e9 + 7;
int main() {
  int n, k;
  cin >> n >> k;
  int ans = n * 3;
  ans += min(k - 1, n - k);
  cout << ans << "\n";
  return 0;
}
