#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  while (a != 0 && b != 0) {
    if (a - b >= b) {
      if ((a / b) % 2 == 0)
        a = a - (a / b) * b;
      else
        a = a - (a / b - 1) * b;
      continue;
    } else {
      if (b - a >= a) {
        if ((b / a) % 2 == 0)
          b = b - (b / a) * a;
        else
          b = b - (b / a - 1) * a;
        continue;
      } else
        break;
    }
  }
  cout << a << " " << b;
  return 0;
}
