#include <bits/stdc++.h>
using namespace std;
int a[105];
int pos, neg;
int main() {
  long long a, b;
  cin >> a >> b;
  while (a != 0 and b != 0) {
    if (a >= 2 * b) {
      a %= 2 * 1LL * b;
    } else if (b >= 2 * a) {
      b %= 2 * 1LL * a;
    } else {
      break;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}
