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