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