#include <bits/stdc++.h>
const int MAX = (const int)(1e5 + 11);
using namespace std;
static void solve(std::int32_t test) {
  int N, K;
  cin >> N >> K;
  if (N == 1) {
    cout << 2;
    return;
  }
  int a = min(K - 1, N - K);
  int b = max(K - 1, N - K);
  cout << 4 * a + 3 * b + 3;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(12) << fixed;
  solve(0);
  return 0;
}
