#include <bits/stdc++.h>
using namespace std;
long long fun(long long a, long long b) {
  if (a % b == 0) return 2 * a - b;
  int c = (int)a / (int)b;
  return 2 * c * b + fun(b, a % b);
};
int main() {
  cout << setprecision(3) << fixed;
  long long a, b;
  cin >> a >> b;
  cout << a + fun(max(a - b, b), min(a - b, b)) << endl;
  return 0;
}
