#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a, b;
  a = k - 1;
  b = n - k;
  int moves = (2 * min(a, b)) + max(a, b);
  int value = 2 * n + 1;
  cout << moves + value << endl;
  return 0;
}
