#include <bits/stdc++.h>
using namespace std;
const int N = 105 + 5;
const int MOD = 1e9 + 7;
int power(int a, int b, int m = MOD) {
  if (b == 0) return 1;
  if (b == 1) return a;
  int x = power(a, b / 2, m) % m;
  x = (x * x) % m;
  if (b % 2) return (x * a) % m;
  return x;
}
long long n, m;
int main() {
  scanf("%lld%lld", &n, &m);
  while (1) {
    if (n < 2 * m && m < 2 * n) break;
    if (n == 0 || m == 0) break;
    if (n >= 2 * m) n = n % (2 * m);
    if (n == 0 || m == 0) break;
    if (m >= 2 * n) m %= (2 * n);
    if (m == 0) break;
  }
  printf("%lld %lld\n", n, m);
  return 0;
}
