#include <bits/stdc++.h>
using namespace std;
long long int a, b;
void dane() {
  cin >> a >> b;
  long long int w = 0;
  while (a != b) {
    if (a < b) swap(a, b);
    w += (a / b);
    if (a % b == 0) {
      w--;
      a = b;
    } else
      a = a % b;
  }
  cout << w + a << "\n";
}
int main() {
  dane();
  return 0;
}
