#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long a = n, b = m;
  while (1) {
    if (a <= 0 || b <= 0) break;
    if (a >= 2 * b) {
      a %= 2 * b;
      continue;
    }
    if (b >= 2 * a) {
      b %= 2 * a;
      continue;
    }
    break;
  }
  cout << a << " " << b << endl;
}
