#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, p = 0;
  cin >> a >> b;
  while (1) {
    if (a == 1) {
      p = p + b;
      break;
    } else if (b == 1) {
      p = p + a;
      break;
    } else if (b > a) {
      p = p + b / a;
      b = b - (a * (b / a));
      if (b == 0) break;
    } else if (a > b) {
      p = p + a / b;
      a = a - (b * (a / b));
      if (a == 0) break;
    } else if (a == b) {
      p++;
      break;
    }
  }
  cout << p;
}
