#include <bits/stdc++.h>
using namespace std;
void showar(long long a[], long long n) {
  cout << "array\n";
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << '\n';
}
void showv(vector<long long> v) {
  cout << "vector\n";
  for (long long i = 0; i < v.size(); i += 1) cout << v[i] << " ";
  cout << '\n';
}
signed main() {
  long long a, b;
  cin >> a >> b;
  while (a != 0 && b != 0) {
    if (a >= 2 * b) a = a % (2 * b);
    if (a == 0) break;
    if (b >= 2 * a) b %= (2 * a);
    if ((b / 2) < a) {
      if (a - b - b < 0) break;
    }
  }
  cout << a << " " << b;
  return 0;
}
