#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  long long ans = 0;
  if (a == b)
    ans = a;
  else
    while ((a > 0) && (b > 0)) {
      double t = (double)a / (double)b;
      long long tt = (long long)t;
      ans += tt;
      a -= b * tt;
      swap(a, b);
    }
  cout << ans << endl;
  return 0;
}
