#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  for (const auto &x : v) os << " " << x;
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << " " << p.second << ')';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  while (n && m) {
    if (n >= 2 * m) {
      n = n % (2 * m);
      continue;
    }
    if (m >= 2 * n) {
      m = m % (2 * n);
      continue;
    } else
      break;
  }
  cout << n << ' ' << m;
}
