#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b;
  int ans = a;
  c = a;
  a = max(c - b, b);
  b = min(c - b, b);
  while (1) {
    c = a % b;
    d = a / b;
    if (c == 0) {
      ans += b * (2 * d - 1);
      break;
    }
    ans += 2 * b * d;
    a = b;
    b = c;
  }
  cout << ans << endl;
  return 0;
}
