#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long a, b, c, ans = 0;
    cin >> a >> b;
    while (a != 0 && b != 0) {
      if (a >= b) {
        c = a / b;
        ans += c;
        a -= b * c;
      } else if (a < b) {
        c = b / a;
        ans += c;
        b -= a * c;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
