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