#include <bits/stdc++.h>
int main() {
  long long a, b, cnt, tmp;
  while (scanf("%I64d %I64d", &a, &b) != EOF) {
    cnt = 0;
    while (a > 0 && b > 0) {
      if (a > b) {
        cnt += (long long)a / b;
        a %= b;
      } else {
        cnt += (long long)b / a;
        b %= a;
      }
    }
    printf("%I64d\n", cnt);
  }
  return 0;
}
