#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
inline int in() {
  int x;
  cin >> x;
  return x;
}
template <class T>
void max_self(T &a, const T &b) {
  if (a < b) a = b;
}
template <class T>
void min_self(T &a, const T &b) {
  if (a > b) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b;
  cin >> a >> b;
  while (a && b) {
    if (a >= 2 * b)
      a %= 2 * b;
    else if (b >= 2 * a)
      b %= 2 * a;
    else
      break;
  }
  cout << a << " " << b;
  return 0;
}
