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