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