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