#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a, b;
  cin >> a >> b;
  ll cnt = 0;
  while (a != 0) {
    if (a > b) {
      cnt = cnt + (a / b);
      a = a % b;
    } else if (a < b) {
      ll t;
      t = a;
      a = b;
      b = t;
    } else {
      cnt++;
      break;
    }
  }
  cout << cnt << "\n";
  return 0;
}
