#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, flag = 0;
  cin >> a >> b;
  long long int min = a, max = b;
  if (b < a) {
    min = b;
    max = a;
    flag++;
  }
label:
  long long int t = min * 2;
  long long int y = max % t;
  if (y == 0 || y * 2 > min) {
    if (flag % 2 == 0)
      cout << min << " " << y;
    else
      cout << y << " " << min;
    return 0;
  } else {
    max = min;
    min = y;
    flag++;
    goto label;
  }
  return 0;
}
