#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
long long a, b, ans = 0;
int main() {
  cin >> a >> b;
  while (b) {
    ans += a / b;
    a %= b;
    swap(a, b);
  }
  cout << ans;
  return 0;
}
