#include <bits/stdc++.h>
using namespace std;
long long N, X, Ans, Y;
int main() {
  scanf("%lld%lld", &N, &X);
  Ans = N;
  Y = N - X;
  while (X != Y) {
    if (X > Y) swap(X, Y);
    Ans += 2 * X;
    Y -= X;
  }
  Ans += X;
  printf("%lld\n", Ans);
  return 0;
}
