#include <bits/stdc++.h>
using namespace std;
long long a, b;
int main(void) {
  scanf("%lld%lld", &a, &b);
  while (a > 0 and b > 0) {
    if (a == 2LL * b) {
      a -= 2LL * b;
    } else if (b == 2LL * a) {
      b -= 2LL * a;
    } else if (a >= 2LL * b) {
      long long k = (a - 2LL * b) / (2LL * b);
      long long r = (a - 2LL * b) % (2LL * b);
      if (r != 0) k++;
      a -= 2LL * b * k;
    } else if (b >= 2LL * a) {
      long long k = (b - 2LL * a) / (2LL * a);
      long long r = (b - 2LL * a) % (2LL * a);
      if (r != 0) k++;
      b -= 2LL * a * k;
    } else {
      break;
    }
  }
  printf("%lld %lld\n", a, b);
  return 0;
}
