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