#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 5;
const int INF = int(1e9) + 7;
const long long MINF = 1e18;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, k;
  cin >> n >> k;
  int sum = 0;
  sum += min(k - 1, n - k);
  sum += (n - 1);
  sum += 3;
  sum += (n - 1) * 2;
  cout << sum;
  return 0;
}
