#include <bits/stdc++.h>
using namespace std;
long long a, b, k, ans;
int main() {
  scanf("%lld %lld", &a, &b);
  while (1) {
    if (a < b) swap(a, b);
    long long kk = a % b;
    k = a / b;
    a -= k * b;
    ans += k;
    if (!kk) break;
  }
  printf("%lld\n", ans);
}
