#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long N, X;
  cin >> N >> X;
  unsigned long long l = N;
  unsigned long long a = X, b = N - X;
  while (a != b) {
    if (a > b) swap(a, b);
    l += 2 * a;
    b -= a;
  }
  l += a;
  cout << l << endl;
  return 0;
}
