#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, i, n, j, k, in, ind, r, l;
  cin >> a;
  cin >> b;
  while (a != 0 && b != 0) {
    if (a >= 2 * b)
      a %= 2 * b;
    else if (b >= 2 * a)
      b %= 2 * a;
    else
      break;
  }
  cout << a << " " << b;
}
