#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long a, b, c, t, d, cnt = 0;
  cin >> a >> b;
  while (a != 1 && b != 1) {
    if (a > b) {
      cnt += a / b;
      a = a % b;
    } else if (b > a) {
      cnt += b / a;
      b = b % a;
    }
  }
  if (a == 1)
    cnt += b;
  else if (b == 1)
    cnt += a;
  cout << cnt << endl;
  return 0;
}
