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