#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f;
long long int gcd(long long int a, long long int b, long long int cnt) {
  if (a == 0) return cnt;
  return gcd(b % a, a, cnt + (b / a));
}
int main() {
  cin >> a >> b;
  d = a / b;
  if (a % b != 0) d += gcd(a % b, b, 0);
  cout << d << "\n";
  return 0;
}
