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