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