#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long c = getchar(), x = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * f;
}
long long a, b, n, m, s, sum1, sum2;
inline void solve3() {
  if (b >= 2 * a) b %= 2 * a;
}
inline void solve2() {
  if (a >= 2 * b)
    a %= 2 * b;
  else
    solve3();
}
inline void solve1() {
  if (a == 0 || b == 0) return;
  solve2();
}
int main(void) {
  a = read(), b = read();
  while (a && b) {
    if (a == 0 || b == 0)
      solve1();
    else if (a >= 2 * b)
      solve2(), solve1();
    else if (b >= 2 * a)
      solve3(), solve1();
    else
      break;
  }
  cout << a << ' ' << b;
  return 0;
}
