#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000005, INFi = 3000000001;
long long n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  while (1) {
    if (n == 0 || m == 0 || (n < m * 2 && m < n * 2))
      return cout << n << " " << m, 0;
    if (n >= m * 2)
      n -= m * 2 * (n / (m * 2));
    else if (m >= n * 2)
      m -= n * 2 * (m / (n * 2));
  }
}
