#include <bits/stdc++.h>
using namespace std;
inline long long CinLL() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline int Cin() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
const int INF = 0x3f3f3f3f;
const int N = 100005;
long long t, n, m, ans;
int a[N];
vector<int> v;
int main() {
  cin >> n >> m;
  while (n != 0 && m != 0) {
    if (n >= 2 * m) {
      n -= (n / (2 * m)) * 2 * m;
    } else if (m >= 2 * n) {
      m -= (m / (2 * n)) * n * 2;
    } else
      break;
  }
  cout << n << " " << m << endl;
  return 0;
}
