#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  scanf("%lld%lld", &a, &b);
  long long int c = a, d = b;
  long long int cnt = 0, rem;
  while (c >= 1 && d >= 1) {
    if (d == 1) {
      printf("%lld", cnt + c);
      return 0;
    }
    if (c >= d) {
      cnt += c / d;
      c = c % d;
    } else {
      cnt += d / c;
      d = d % c;
    }
  }
  printf("%lld\n", cnt);
  return 0;
}
