#include <bits/stdc++.h>
using namespace std;
struct data {
  unsigned long long a, b;
};
struct data f(unsigned long long a, unsigned long long b) {
  data ret;
  ret.a = a;
  ret.b = b;
  if (a == 0 or b == 0) return ret;
  if (a >= b * 2) return f(a % (b * 2), b);
  if (b >= a * 2)
    return f(a, b % (a * 2));
  else
    return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  unsigned long long a, b;
  cin >> a >> b;
  data ans = f(a, b);
  cout << ans.a << " " << ans.b << '\n';
}
