#include <bits/stdc++.h>
using namespace std;
const int INF = 600000000;
const long long mod = 1000000007;
const double pi = acos(-1.0);
const double EPS = 1e-11;
string toStr(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
int toNum(string s) {
  stringstream ss;
  long long n;
  ss << s;
  ss >> n;
  return n;
}
long long ans = 0;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else {
    ans += a / b;
    return gcd(b, a % b);
  }
}
int main() {
  long long a, b;
  cin >> a >> b;
  gcd(a, b);
  cout << ans << endl;
  return 0;
}
