#include <bits/stdc++.h>
using namespace std;
inline void pr(int n) { printf("%d\n", n); }
const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},
                       {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int i = 0; i < ((int)((t).size())); i++) s << t[i] << " ";
  return s;
}
long long counter = 0;
int gcd(long long a, long long b) {
  if (b < a) swap(a, b);
  if (a == 0) return 1;
  counter += b / a;
  return gcd(b % a, a);
}
int main() {
  long long a, b;
  cin >> a >> b;
  gcd(a, b);
  cout << counter;
}
