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