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