#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_1-B
?????§??¬?´???°

??????????????¶??° x, y ?????\?????¨???????????????????????§??¬?´???°????±???????????????°????????????????????????????????????

???????????´??° x ??¨ y ???????????????x ?? d ??¨ y ?? d ??????????????¨?????? 0 ??¨?????? d ??????????????§???????????????x ??¨ y ????????§??¬?´???°???Greatest Common Divisor?????¨?¨?????????????????????°???35 ??¨14 ????????§??¬?´???° gcd (35, 14) ??? 7 ??¨???????????????????????????35 ????´???°{1, 5, 7, 35}???14 ????´???° {1, 2, 7, 14} ?????¬?´???° {1, 7} ????????§?????¨???????????????
??\???

x ??¨ y ?????????????????????????????§??????????????????????????????
??????

?????§??¬?´???°???????????????????????????????????????
??¶?´?

    1 ??? x, y ??? 109

?????????

??´??° x, y ???????????????x ??\ y ????????° x ??¨ y ????????§??¬?´???°??? y ??¨ x % y ????????§??¬?´???°???????????????????????§ x % y ??? x ??? y ??§?????£???????????§????????????
??\?????? 1

147 105

??\?????? 1 ??????????????????

21

=end
def gcd1(a, b)
  a.gcd(b)
end

def gcd2(a, b)
  if b==0 then
    a
  else
    gcd2(b, a % b)
  end
end

class Main
  def initialize
    fh = STDIN
    v=[]
    v = fh.gets.chomp.split.map{|x| x.to_i}
    puts gcd2(v[0],v[1])
  end
end

if $0==__FILE__ then
  Main.new()
end