#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long p, q, a, b;
  cin >> a >> b;
  if (a == 0 || b == 0) {
    cout << a << ' ' << b;
  }
  while (1) {
    if (max(a, b) < 2 * min(a, b) || (a == 0 || b == 0)) {
      cout << a << ' ' << b;
      break;
    } else if (a > b) {
      p = a / b;
      p = p - (p & 1);
      a -= p * b;
    } else if (a < b) {
      p = b / a;
      p = p - (p & 1);
      b -= p * a;
    }
  }
  return 0;
}
