#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 3;
const double EPS = 1e-13;
const int64_t MOD = (int64_t)1e9 + 123;
int64_t compute(int64_t a, int64_t b) {
  int64_t res = 0;
  while (a != 0 and b != 0) {
    if (a > b) {
      res += a / b;
      a %= b;
    } else {
      res += b / a;
      b %= a;
    }
  }
  return res;
}
void test0() {
  int64_t a, b;
  scanf("%" PRId64 "%" PRId64, &a, &b);
  printf("%" PRId64 "\n", compute(a, b));
}
int main() {
  clock_t start = clock();
  test0();
  double time = (clock() - start) / (double)CLOCKS_PER_SEC * 1000;
  fprintf(stderr, "Time: %f ms\n", time);
  return 0;
}
