#include <bits/stdc++.h>
long long a, b, c, i, ans;
int main() {
  scanf("%I64d%I64d", &a, &b);
  ans = 0;
  for (i = 0;; i++) {
    if (a < b) {
      long long t = a;
      a = b;
      b = t;
    }
    c = a / b;
    ans += c;
    if (a % b == 0) break;
    a = a - c * b;
  }
  printf("%I64d\n", ans);
  return 0;
}
