#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, m;
  cin >> n >> m;
  while (1) {
    if (n == 0 || m == 0)
      break;
    else if (n >= 2ULL * m) {
      n = n % (2ULL * m);
    } else if (m >= 2ULL * n) {
      m = m % (2ULL * n);
    } else {
      break;
    }
  }
  cout << n << " " << m << endl;
}
