#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long double eps = 0.0000000001;
const long long INF = 0x3fffffffffffffff;
long long a, b;
long long workgcd(long long A, long long B) {
  return B ? A / B + workgcd(B, A % B) : 0;
}
signed main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  cout << workgcd(a, b) << endl;
  return 0;
}
