#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int sz = 505;
const ll inf = 1e18;
const int lim = 1 << 8;
int n, k;
int ans;
int main() {
  while (scanf("%d %d", &n, &k) == 2) {
    ans = n + n;
    ans += max(min(n - k, k - 1), 0) * 2;
    ans += max(max(n - k, k - 1), 0);
    ans += 1;
    cout << ans << "\n";
    cerr << "-----\n";
  }
  return 0;
}
