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