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