let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const [x, y] = content
    .trim()
    .split(' ')
    .map(n => +n);
  console.log(gcd(x, y));
});

const gcd = (x, y) => {
  if (x === 0 || y === 0) {
    return x || y;
  }

  // ensure x >= y
  if (x < y) {
    const tmp = x;
    x = y;
    y = tmp;
  }

  return gcd(y, x % y);
};
