a, b = gets.split.collect(&:to_i)
while true
  if a == 0
    puts b
    break
  elsif b == 0
    puts a
    break
  elsif a < b
    b = b % a
  elsif a > b
    a = a % b
  else
    puts a
    break
  end
end