#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, count = 0;
  cin >> a >> b;
  while (a > 0 && b > 0) {
    count += a / b;
    a = a % b;
    swap(a, b);
  }
  cout << count;
  return 0;
}
