#include <bits/stdc++.h>
using namespace std;
int compareAscending(const void *a, const void *b) {
  return (*(int *)a - *(int *)b);
}
int compareDecending(const void *a, const void *b) {
  return (*(int *)b - *(int *)a);
}
int compareFirst(const void *a, const void *b) {
  if (((pair<int, int> *)a)->first == ((pair<int, int> *)b)->first)
    return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second;
  else
    return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first;
}
int compareSecond(const void *a, const void *b) {
  if (((pair<int, int> *)a)->second == ((pair<int, int> *)b)->second)
    return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first;
  else
    return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second;
}
bool isPrime(int a) {
  if (a < 2) return false;
  if (a < 4) return true;
  if (a % 2 == 0) return false;
  int s = (int)sqrt(a);
  for (int i = 3; i <= s; i += 2) {
    if (a % i == 0) return false;
  }
  return true;
}
int bsearch(int *a, int value, int l, int r) {
  if (l == r) return l;
  if (l + 1 == r) return a[l] >= value ? l : r;
  int m = (l + r) / 2;
  if (a[m] >= value)
    return bsearch(a, value, l, m);
  else
    return bsearch(a, value, m + 1, r);
}
int main() {
  long long a, b, res = 0, t;
  scanf("%lld %lld", &a, &b);
  while (a != 0 && b != 0) {
    res += a / b;
    t = a % b;
    a = b;
    b = t;
  }
  printf("%lld", res);
  return 0;
}
