#include <bits/stdc++.h>
using namespace std;
long long answer = 0;
long long gcd(long long a, long long b) {
  if (b != 0) answer += a / b;
  return b ? gcd(b, a % b) : a;
}
void solution() {
  long long a, b;
  cin >> a >> b;
  gcd(a, b);
  cout << answer << "\n";
}
int main() {
  solution();
  return 0;
}
