#include <bits/stdc++.h>
using namespace std;
long long n, m;
int main() {
  while (scanf("%I64d %I64d", &n, &m) != EOF) {
    while (1) {
      if (n == 0 | m == 0) break;
      if (n >= 2 * m)
        n = n % (2 * m);
      else if (m >= 2 * n)
        m = m % (2 * n);
      else
        break;
    }
    printf("%I64d %I64d\n", n, m);
  }
  return 0;
}
