# -*- coding: utf-8 -*-


def converter(a, b):
    larger = max(a, b)
    smaller = min(a, b)
    if larger == 0 or smaller == 0:
        return larger
    else:
        return converter(smaller, larger % smaller)        


def main():
    a, b = [int(x) for x in raw_input().strip().split(' ')]
    print converter(a, b) 


if __name__ == '__main__':
    main() def converter(a, b):
    larger = max(a, b)
    smaller = min(a, b)
    if larger == 0 or smaller == 0:
        return larger
    else:
        return converter(smaller, larger % smaller)         converter larger = max(a, b) larger max(a, b) max a b smaller = min(a, b) smaller min(a, b) min a b if larger == 0 or smaller == 0:
        return larger
    else:
        return converter(smaller, larger % smaller)         larger == 0 or smaller == 0 larger == 0 larger 0 smaller == 0 smaller 0 return larger larger return converter(smaller, larger % smaller) converter(smaller, larger % smaller) converter smaller larger % smaller larger smaller a a b b def main():
    a, b = [int(x) for x in raw_input().strip().split(' ')]
    print converter(a, b)  main int(x) for x in raw_input().strip().split(' ') for x in raw_input().strip().split(' ') x raw_input().strip().split(' ') ().strip().split ().strip() ().strip () raw_input strip split ' ' for x in raw_input().strip().split(' ') int(x) int x a, b = [int(x) for x in raw_input().strip().split(' ')] a [int(x) for x in raw_input().strip().split(' ')] b print converter(a, b) converter a b if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    a, b = [int(x) for x in raw_input().strip().split(' ')]
    print converter(a, b)  def main():
    a, b = [int(x) for x in raw_input().strip().split(' ')]
    print converter(a, b)  main def converter(a, b):
    larger = max(a, b)
    smaller = min(a, b)
    if larger == 0 or smaller == 0:
        return larger
    else:
        return converter(smaller, larger % smaller)         def converter(a, b):
    larger = max(a, b)
    smaller = min(a, b)
    if larger == 0 or smaller == 0:
        return larger
    else:
        return converter(smaller, larger % smaller)         converter
# -*- coding: utf-8 -*-


def converter(a, b):
    larger = max(a, b)
    smaller = min(a, b)
    if larger == 0 or smaller == 0:
        return larger
    else:
        return converter(smaller, larger % smaller)        


def main():
    a, b = [int(x) for x in raw_input().strip().split(' ')]
    print converter(a, b) 


if __name__ == '__main__':
    main()