#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  long long a, b;
  cin >> a >> b;
  bool kek = 0;
  while (1) {
    if (a == 0 || b == 0) break;
    if (a < b) {
      swap(a, b);
      kek = !kek;
    }
    if (a >= 2 * b) {
      a -= a / (2 * b) * (2 * b);
    } else {
      break;
    }
  }
  if (kek)
    cout << b << " " << a;
  else
    cout << a << " " << b;
  return 0;
}
