#include <bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b) {
  if (a == 0 || b == 0) return 0;
  if (a == b) return 1;
  if (a > b) return a / b + solve(a % b, b);
  return b / a + solve(a, b % a);
}
int main() {
  long long a, b;
  cin >> a >> b;
  cout << solve(a, b) << "\n";
  return 0;
}
