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