#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long sum = 0;
  if (a < b) {
    long long temp = a;
    a = b;
    b = temp;
  }
  while (b != 0) {
    sum += a / b;
    long long temp = a % b;
    a = b;
    b = temp;
  }
  return sum;
}
int main() {
  long long a, b;
  cin >> a >> b;
  cout << gcd(a, b);
}
