#include <bits/stdc++.h>
const int MOD = 1000000007;
const int MXN = 100010;
int main() {
  register int i;
  register long long a, b, n, x, ans = 0;
  scanf("%lld%lld", &n, &x);
  ans = n;
  a = n - x, b = x;
  while (a != 0 && b != 0) {
    if (a > b) std::swap(a, b);
    ans += 2 * a, b -= a;
  }
  printf("%lld ", ans + 1);
  return 0;
}
