#include <bits/stdc++.h>
using namespace std;
long long a, b, ans;
inline void gcd(long long x, long long y) {
  if (!y) return;
  ans += x / y;
  gcd(y, x % y);
}
signed main() {
  cin >> a >> b;
  gcd(a, b);
  printf("%lld", ans);
  return 0;
}
