#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> rec(long long a, long long b) {
  if (a == 0 || b == 0) return make_pair(a, b);
  if (a >= 2 * b) {
    if (a <= 2 * b)
      return rec(a - 2 * b, b);
    else
      return rec(a % (2 * b), b);
  } else if (b >= 2 * a) {
    if (b <= 2 * a) return rec(a, b - 2 * a);
    return rec(a, b % (2 * a));
  } else
    return make_pair(a, b);
}
int main() {
  ios::sync_with_stdio(false);
  long long a, b;
  cin >> a >> b;
  pair<long long, long long> prin = rec(a, b);
  cout << prin.first << ' ' << prin.second << endl;
  return 0;
}
