#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 24;
const int mod = 1e9 + 7;
int n, m;
long long gcd(long long a, long long b) {
  if (b == 0 or a == 0) return 0;
  if (b > a) return gcd(b, a);
  return a / b + gcd(a % b, b);
}
int main() {
  int t, q;
  long long a, b, x, y;
  cin >> a >> b;
  cout << gcd(a, b);
}
