#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
long long int vis[N];
vector<vector<int> > v;
int dfs(int t) {
  vis[t] = 1;
  for (int i = 0; i < v[t].size(); i++) {
    if (vis[v[t][t]] == 0) {
      dfs(v[t][i]);
    }
  }
  return 0;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int main() {
  long long int n, m;
  cin >> n >> m;
  while (1) {
    if (n == 0 or m == 0) break;
    if (n >= 2 * m)
      n = n % (2 * m);
    else if (m >= 2 * n)
      m = m % (2 * n);
    else
      break;
  }
  cout << n << " " << m << endl;
  return 0;
}
