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