#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int temp, a, b, c, i, j = 1, k = 0;
  cin >> a >> b;
  while (a != 1 && b != 1) {
    k += a / b;
    if (a % b == 0) {
      k += a / b;
      break;
    }
    temp = a;
    a = b;
    b = temp % b;
  }
  if (a == 1)
    k += b;
  else if (b == 1)
    k += a;
  cout << k << endl;
  return 0;
}
