#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  long long int answer = 0, temp;
  cin >> a >> b;
  long long int maxim = max(a, b);
  long long int minim = min(a, b);
  if (b == 1 || a == 1) {
    answer = maxim;
    cout << answer << endl;
  } else {
    while (minim > 1) {
      answer += maxim / minim;
      temp = minim;
      minim = maxim % temp;
      maxim = temp;
    }
    cout << answer + maxim << endl;
  }
  return 0;
}
