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