def greatest_common_divisor(a, b):
  if a == 0 or b == 0:
    return max(a, b)

  return greatest_common_divisor(max(a, b) - min(a, b), min(a, b))

a, b = map(int, input().split())
print(greatest_common_divisor(a, b)) def greatest_common_divisor(a, b):
  if a == 0 or b == 0:
    return max(a, b)

  return greatest_common_divisor(max(a, b) - min(a, b), min(a, b)) greatest_common_divisor if a == 0 or b == 0:
    return max(a, b)

   a == 0 or b == 0 a == 0 a 0 b == 0 b 0 return max(a, b) max(a, b) max a b return greatest_common_divisor(max(a, b) - min(a, b), min(a, b)) greatest_common_divisor(max(a, b) - min(a, b), min(a, b)) greatest_common_divisor max(a, b) - min(a, b) max(a, b) max a b min(a, b) min a b min(a, b) min a b a a b b a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b print(greatest_common_divisor(a, b)) print greatest_common_divisor(a, b) greatest_common_divisor a b a, b = map(int, input().split()) map(int, input().split()) a b = map(int, input().split()) map(int, input().split()) b def greatest_common_divisor(a, b):
  if a == 0 or b == 0:
    return max(a, b)

  return greatest_common_divisor(max(a, b) - min(a, b), min(a, b)) def greatest_common_divisor(a, b):
  if a == 0 or b == 0:
    return max(a, b)

  return greatest_common_divisor(max(a, b) - min(a, b), min(a, b)) greatest_common_divisor
def greatest_common_divisor(a, b):
  if a == 0 or b == 0:
    return max(a, b)

  return greatest_common_divisor(max(a, b) - min(a, b), min(a, b))

a, b = map(int, input().split())
print(greatest_common_divisor(a, b))