#include <bits/stdc++.h>
using namespace std;
char symmetric[11] = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'};
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool IsPalindrome(string str) {
  if (str.empty()) return false;
  long long int i = 0;
  long long int j = str.length() - 1;
  while (i < j) {
    if (str[i] != str[j]) {
      return false;
    }
    i++;
    j--;
  }
  return true;
}
long long int binpow(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int res = binpow(a, b / 2);
  if (b % 2) return (res * res * a);
  return (res * res);
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int a, b;
  cin >> a >> b;
  long long int x = max(a, b);
  long long int y = a + b - x;
  if (a < 2 * b && b < 2 * a)
    cout << a << " " << b;
  else if (x % y == 0) {
    if ((x / y) % 2 == 0) {
      if (y == a) {
        cout << y << " 0";
      } else {
        cout << "0 " << y;
      }
    } else {
      cout << y << " " << y;
    }
  } else {
    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;
}
