#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> s(long long& a, long long& b) {
  if (a == 0 || b == 0)
    return {a, b};
  else if (a >= 2 * b) {
    a %= 2 * b;
    return s(a, b);
  } else if (b >= 2 * a) {
    b %= 2 * a;
    return s(a, b);
  }
  return {a, b};
}
int main() {
  long long a, b;
  pair<long long, long long> n;
  cin >> a >> b;
  n = s(a, b);
  cout << n.first << ' ' << n.second;
  return 0;
}
