#include <bits/stdc++.h>
int const N = 105;
int const M = 205;
int const inf = 1000000000;
long long const mod = 1000000007;
using namespace std;
long long a, b;
long long ans;
void ini() { ans = 0; }
void gcd(long long a, long long b) {
  if (b == 0) {
    return;
  }
  ans += a / b;
  gcd(b, a % b);
}
void solve() { gcd(a, b); }
void out() { printf("%I64d\n", ans); }
int main() {
  while (scanf("%I64d%I64d", &a, &b) != EOF) {
    ini();
    solve();
    out();
  }
}
