#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x = 0, Max = 100000000000;
  cin >> a >> b;
  while (Max--) {
    if (b == 0) {
      break;
    }
    x += a / b;
    a = a % b;
    swap(a, b);
  }
  cout << x;
  return 0;
}
