#include <bits/stdc++.h>
using namespace std;
int dx8[] = {-1, 0, +1, -1, +1, -1, 0, +1};
int dy8[] = {+1, +1, +1, 0, 0, -1, -1, -1};
int dx4[] = {0, -1, +1, 0};
int dy4[] = {+1, 0, 0, -1};
int dxkn[] = {1, -1, 1, -1, 2, -2, -2, 2};
int dykn[] = {2, 2, -2, -2, 1, 1, -1, -1};
int main() {
  long long n, m, i, d;
  cin >> n >> m;
  for (i = 1;; i++) {
    if (n == 0 || m == 0) {
      cout << n << " " << m << endl;
      return 0;
    } else if (n >= 2 * m) {
      d = n / (2 * m);
      n -= (d * 2 * m);
    } else if (m >= 2 * n) {
      d = m / (2 * n);
      m -= (d * 2 * n);
    } else {
      cout << n << " " << m << endl;
      return 0;
    }
  }
  return 0;
}
