#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, s = 0;
  cin >> a >> b;
  while (b > 1) {
    if (b > a) swap(a, b);
    s += a / b;
    a -= (b * (a / b));
    if (a < 1) break;
  }
  s += a;
  cout << s << endl;
  return 0;
}
