#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
int main() {
  long long int a, b, ans = 0;
  cin >> a >> b;
  while (a != 0 && b != 0) {
    if (a > b) {
      ans += (a / b);
      a = a - (a / b) * b;
    } else if (b > a) {
      ans += (b / a);
      b = b - (b / a) * a;
    } else if (a == b) {
      ans += a;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
