#include <bits/stdc++.h>
using namespace std;
int main() {
  int l, x, a, suma = 0;
  bool loop = true;
  cin >> l >> x;
  vector<int> luz;
  suma += x;
  luz.push_back(x);
  a = l - x;
  suma += a;
  luz.push_back(a);
  while (loop) {
    sort(luz.begin(), luz.end());
    if (luz[1] % luz[0] == 0) loop = false;
    a = luz[1] / luz[0];
    luz[1] -= a * luz[0];
    a *= 2;
    if (!loop) a--;
    a *= luz[0];
    suma += a;
  }
  cout << suma << endl;
  return 0;
}
