#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long a, b, cnt = 0;
  cin >> a >> b;
  while (a != 0 && b != 0) {
    if (b > a) {
      swap(a, b);
    }
    cnt += a / b;
    a %= b;
  }
  cout << cnt;
}
