#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, p = 0, m;
  cin >> n >> k;
  p = p + n + (n - 2) + min(k - 1 + n - 1, (n - k - 1 + n)) + 3;
  cout << p << endl;
  return 0;
}
