#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  long long a, b, c = 0;
  cin >> a >> b;
  if (a < b) swap(a, b);
  while (b != 0) {
    c += a / b;
    a %= b;
    swap(a, b);
  }
  cout << c << endl;
  return 0;
}
