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