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