#include <bits/stdc++.h>
using namespace std;
long long n, m;
void gcd(long long a, long long b) {
  if (a == 0 || b == 0) {
    printf("%lld %lld", a, b);
    exit(0);
  } else if (a >= 2 * b)
    return gcd(a - (a / (2 * b)) * 2 * b, b);
  else if (b >= 2 * a)
    return gcd(a, b - (b / (2 * a)) * 2 * a);
  else {
    printf("%lld %lld", a, b);
    exit(0);
  }
}
int main() {
  scanf("%lld %lld", &n, &m);
  gcd(n, m);
  return 0;
}
