#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  long long m, n, i, j, k, l, ans = 0;
  cin >> n >> m;
  while (n && m) {
    if (n > m) {
      ans += (n / m);
      n = n % m;
    } else {
      ans += (m / n);
      m = m % n;
    }
  }
  cout << ans;
  return 0;
}
