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