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