#include <bits/stdc++.h>
using namespace std;
int dir[8][2] = {{1, 1},   {1, 0},  {1, -1}, {0, -1},
                 {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}};
int dir2[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
int main() {
  long long a, b;
  cin >> a >> b;
  long long ans = 0;
  if (b == 1) {
    cout << a << endl;
    return 0;
  }
  long long tmp;
  while (a != b && a && b) {
    if (a > b) {
      tmp = (a / b);
      ans += tmp;
      a -= tmp * b;
    } else {
      tmp = (b / a);
      ans += tmp;
      b -= tmp * a;
    }
  }
  cout << ans << endl;
}
