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