#include <bits/stdc++.h>
using namespace std;
int N, K;
int main() {
  cin >> N >> K;
  if (K > N - K + 1) K = N - K + 1;
  if (N == 1)
    cout << "2\n";
  else
    cout << K - 1 + N - 1 + K + K + N - K + N - K + 1;
  return 0;
}
