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