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