#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x, y;
  cin >> x >> y;
  while (1) {
    if (x % (2 * y) == 0) {
      cout << 0 << " " << y;
      break;
    } else if (y % (2 * x) == 0) {
      cout << x << " " << 0;
      break;
    }
    x = x % (2 * y);
    y = y % (2 * x);
    if (x == 0 || y == 0) {
      cout << x << " " << y;
      break;
    } else if ((x / y) <= 1 && (y / x) <= 1) {
      cout << x << " " << y;
      break;
    }
  }
  return 0;
}
