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