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