#include <bits/stdc++.h>
using namespace std;
template <typename T>
void write(vector<T> &a) {
  for (auto it = a.begin(); it != a.end(); it++) cout << *it << " ";
  cout << "\n";
}
void random(long long int a, long long int b, long long int n) {
  srand(time(0));
  for (long long int i = 0; i < n; i++) cout << rand() % b + a << " ";
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(15);
  {
    long long int n, m;
    cin >> n >> m;
    while (1) {
      if (n == 0 || m == 0) break;
      if (n >= 2 * m) {
        n %= 2 * m;
      } else if (m >= 2 * n) {
        m %= 2 * n;
      } else
        break;
    }
    cout << n << " " << m << "\n";
  }
  return 0;
}
