#include <bits/stdc++.h>
using namespace std;
long long int sum, a, b, t;
int main() {
  scanf("%I64d%I64d", &a, &b);
  if (a < b) a ^= b ^= a ^= b;
  while (b != 0) {
    sum += a / b;
    a %= b;
    a ^= b ^= a ^= b;
  }
  printf("%I64d\n", sum);
  return 0;
}
