#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
const double EPS = 1e-6;
const int INF = (2e9);
const long long P = 1e9 + 7;
int main() {
  std::ios::sync_with_stdio(false);
  long long a, b;
  cin >> a >> b;
  long long sum = 0;
  while (a && b) {
    if (a > b) swap(a, b);
    sum += b / a;
    b = b % a;
  }
  cout << sum << endl;
  return 0;
}
