#include <bits/stdc++.h>
using namespace std;
void inline st_prog() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  st_prog();
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  if (k > n / 2) {
    k = n - k + 1;
  }
  cnt += 3 * n;
  cnt += k + 1;
  cnt -= 2;
  cout << cnt << endl;
  return 0;
}
