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