"""
最大公約数を求める
"""
def gcd(a, b):
    while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
    return a+b

if __name__ == '__main__':
    x, y = map(int, input().split())
    print(gcd(x,y))
 """
最大公約数を求める
""" def gcd(a, b):
    while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
    return a+b gcd while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
     a != 0 and b != 0 a != 0 a 0 b != 0 b 0 if (a >= b):
            a = a % b
        else:
            b = b % a
     a >= b a b a = a % b a a % b a b b = b % a b b % a b a return a+b a+b a b a a b b if __name__ == '__main__':
    x, y = map(int, input().split())
    print(gcd(x,y)) __name__ == '__main__' __name__ '__main__' x, y = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y print(gcd(x,y)) print gcd(x,y) gcd x y def gcd(a, b):
    while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
    return a+b def gcd(a, b):
    while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
    return a+b gcd x, y = map(int, input().split()) map(int, input().split()) x y = map(int, input().split()) map(int, input().split()) y
"""
最大公約数を求める
"""
def gcd(a, b):
    while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
    return a+b

if __name__ == '__main__':
    x, y = map(int, input().split())
    print(gcd(x,y))

