#include <bits/stdc++.h>
using namespace std;
unsigned long long int ans = 0;
int gcd(unsigned long long int a, unsigned long long int b) {
  if ((a == 0) || (b == 0))
    return 0;
  else if (a > b) {
    ans += a / b;
    gcd(b, a % b);
  } else
    gcd(b, a);
  return 0;
}
int main() {
  unsigned long long int a, b;
  cin >> a >> b;
  if ((a == 1) && (b == 1)) {
    cout << 1;
    return 0;
  } else if ((a == 1) && (a != b)) {
    cout << b;
    return 0;
  } else if ((b == 1) && (a != b)) {
    cout << a;
    return 0;
  } else
    gcd(a, b);
  cout << ans;
  return 0;
}
