#include <bits/stdc++.h>
using namespace std;
unsigned long long int a, b, c, ct;
int main() {
  cin >> a >> b;
  while (a % b) {
    ct += (a / b), a %= b;
    c = a, a = b, b = c;
  }
  ct += (a / b);
  cout << ct << endl;
  return 0;
}
