#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int a[125];
int main() {
  long long a, b;
  long long state;
  cin >> a >> b;
  while (1) {
    if (a == 0 || b == 0) {
      break;
    }
    if (a >= 2 * b) {
      long long n = (a / (2 * b));
      a = a - 2 * n * b;
      continue;
    }
    if (b >= 2 * a) {
      long long n = (b / (2 * a));
      b = b - 2 * a * n;
      continue;
    }
    break;
  }
  cout << a << " " << b;
  return 0;
}
