#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  if (k == 1 || k == n)
    printf("%d\n", 3 * n);
  else
    printf("%d\n", 3 * n + min(k - 1, n - k));
  return 0;
}
