#include <bits/stdc++.h>
const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;
using namespace std;
int main() {
  long long a, b, ans;
  cin >> a >> b;
  while (a > 0 && b > 0) {
    ans += a / b;
    a %= b;
    swap(a, b);
  }
  cout << ans;
  return 0;
}
