#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t a, b, amount = 0, buff;
  cin >> a >> b;
  while (a != 0) {
    if (a > b) {
      amount += a / b;
      a %= b;
    } else {
      amount++;
      buff = b;
      b = a;
      a = buff - b;
    }
  }
  cout << amount << endl;
  return 0;
}
