#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
void solve(long long a, long long b) {
  if (a == 0 || b == 0) {
    cout << a << " " << b << endl;
    return;
  }
  long long t1 = a / (b * 2);
  long long t2 = b / (2 * a);
  if (t1 > 0) {
    a -= b * 2 * t1;
    solve(a, b);
  } else if (t2 > 0) {
    b -= a * 2 * t2;
    solve(a, b);
  } else {
    cout << a << " " << b << endl;
    return;
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  solve(n, m);
}
