n, m = map(int, input().split())
if n < m:
    n, m = m, n
while n % m != 0:
    n, m = m, n % m
print(m)