#include <bits/stdc++.h>
using namespace std;
long long n, m;
inline long long read() {
  long long res = 0, f_f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f_f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = (res << 3) + (res << 1) + ch - '0';
    ch = getchar();
  }
  return res * f_f;
}
int main() {
  n = read(), m = read();
  while (n && m) {
    if (n >= m * 2)
      n %= m * 2;
    else if (m >= n * 2)
      m %= n * 2;
    else
      break;
  }
  printf("%lld %lld\n", n, m);
  return 0;
}
