#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int moves = 0;
  int left = k - 1, right = n - k;
  moves += 3 * min(left, right);
  moves += min(left, right);
  moves += 3 * max(left, right);
  moves += 3;
  cout << moves;
}
