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