#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  cin >> a >> b;
  long long int counter = 0;
  long long int temp;
  while (true) {
    if (a > b) {
      counter += a / b;
      a = a % b;
      if (a == 0) break;
    } else if (a == b) {
      counter++;
      break;
    } else {
      temp = a;
      a = b;
      b = temp;
    }
  }
  cout << counter;
  return 0;
}
