#include <bits/stdc++.h>
int main() {
  double n, x;
  int length;
  if (scanf("%lf%lf", &n, &x) >= 2) {
    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;
}
