#include <bits/stdc++.h>
#pragma GCC optimize("O3")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1},
                            {-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
long long a, b;
long long x = 0;
pair<long long, long long> f(long long a, long long b) {
  if (a < b) {
    swap(a, b);
    x = !x;
  }
  if (a == 0 || b == 0) return make_pair(a, b);
  if (a < 2 * b) return make_pair(a, b);
  a -= ((a) / (2 * b)) * 2 * b;
  return f(a, b);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> a >> b;
  auto it = f(a, b);
  if (x) return cout << it.second << ' ' << it.first, 0;
  return cout << it.first << ' ' << it.second, 0;
}
