#include <bits/stdc++.h>
using namespace std;
long long int a, b;
void f1();
void f2();
void f3();
void f1() {
  if (a == 0 || b == 0) {
    printf("%lld %lld", a, b);
    exit(0);
  } else
    f2();
}
void f2() {
  if (a >= 2 * b) {
    a %= 2 * b;
    f1();
  } else
    f3();
}
void f3() {
  if (b >= 2 * a)
    b %= 2 * a, f1();
  else {
    printf("%lld %lld", a, b);
    exit(0);
  }
}
int main() {
  scanf("%lld%lld", &a, &b);
  f1();
  return printf("%lld %lld", a, b), 0;
}
