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