#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long t, n, k, i, j, l, m, u, a, b, x, y, z;
  string s;
  cin >> a >> b;
  k = 1;
  while (1) {
    if (k == 1) {
      if (a == 0 || b == 0) {
        cout << a << " " << b << endl;
        break;
      } else
        k = 2;
    } else if (k == 2) {
      if (a >= 2 * b) {
        a %= 2 * b;
        k = 1;
      } else
        k = 3;
    } else {
      if (b >= 2 * a) {
        b %= 2 * a;
        k = 1;
      } else {
        cout << a << " " << b << endl;
        break;
      }
    }
  }
  return 0;
}
