#include <bits/stdc++.h>
using namespace std;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
int main() {
  long long a, b;
  cin >> a >> b;
  while (true) {
    if (a == 0 || b == 0) break;
    if (a >= 2LL * b) {
      a = a - a / (2LL * b) * (2LL * b);
    } else if (b >= 2LL * a) {
      b = b - b / (2LL * a) * (2LL * a);
    } else {
      break;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}
