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