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