#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, rep;
  cin >> n >> m;
  while (n && m) {
    if (n >= 2 * m) {
      rep = n / (2 * m);
      if (n - rep * (2 * m) >= 0)
        n -= 2 * m * rep;
      else
        break;
    } else if (m >= 2 * n) {
      rep = m / (2 * n);
      if (m - rep * 2 * n >= 0)
        m -= 2 * n * rep;
      else
        break;
    } else
      break;
  }
  cout << n << " " << m;
}
