#include <bits/stdc++.h>
int main(void) {
  int n, x, a, b, sum, tmp;
  scanf("%d %d", &n, &x);
  sum = n;
  a = ((x) > (n - x) ? (x) : (n - x));
  b = ((x) < (n - x) ? (x) : (n - x));
  while (a != b) {
    sum += 2 * b;
    if (a - b >= b) {
      a -= b;
    } else {
      tmp = b;
      b = a - b;
      a = tmp;
    }
  }
  sum += b;
  printf("%d", sum);
  return 0;
}
