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