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