#include <bits/stdc++.h>
int main() {
  long long int a, b, x, c = 0;
  scanf("%lld %lld", &a, &b);
  while (a != 0) {
    if (a < b) {
      x = a;
      a = b;
      b = x;
    }
    c = c + (a / b);
    a = a % b;
  }
  printf("%lld", c);
  return 0;
}
