#include <bits/stdc++.h>
const int INF = 1e9 + 7;
using namespace std;
int a[10001];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  if (n == 0 or m == 0) {
    cout << n << " " << m;
    return 0;
  }
  while (n != 0 and m != 0) {
    if (n >= 2 * m) {
      n -= (n / (2 * m) * (2 * m));
    } else {
      if (m >= 2 * n)
        m %= 2 * n;
      else {
        cout << n << " " << m;
        return 0;
      }
    }
  }
  cout << n << " " << m;
  return 0;
}
