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