#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int main() {
  long long a, b;
  scanf("%lld", &a);
  scanf("%lld", &b);
  while (a > 0 && b > 0 && (a >= 2 * b || b >= 2 * a))
    if (a >= 2 * b)
      a %= 2 * b;
    else
      b %= 2 * a;
  printf("%lld %lld\n", a, b);
}
