#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b;
  while (true) {
    if (a == 0 or b == 0)
      break;
    else if (a >= 2 * b) {
      long long k = (a - 2 * b) / (2 * b) + 1;
      a -= 2 * b * k;
    } else if (b >= 2 * a) {
      long long k = (b - 2 * a) / (2 * a) + 1;
      b -= 2 * a * k;
    } else
      break;
  }
  printf("%lld %lld\n", a, b);
}
