from heapq import heapify, heappop, heappush



n = int(eval(input()))

a = list(map(int, input().split()))

heapify(a)



while len(a) > 1:

    a1, a2 = heappop(a), heappop(a)

    m = a2 % a1

    heappush(a, a1)

    if m:

        heappush(a, m)

print((heappop(a)))
from fractions import gcd

from functools import reduce



n = int(eval(input()))

a = list(map(int, input().split()))

answer = reduce(gcd, a)

print(answer)
from heapq import heapify, heappop, heappush

n = int(eval(input()))
a = list(map(int, input().split()))
heapify(a)
while len(a) > 1:
    a1, a2 = heappop(a), heappop(a)
    m = a2 % a1
    heappush(a, a1)
    if m:
        heappush(a, m)
print((heappop(a)))

from fractions import gcd
from functools import reduce

n = int(eval(input()))
a = list(map(int, input().split()))
answer = reduce(gcd, a)
print(answer)

-from heapq import heapify, heappop, heappush +from fractions import gcd +from functools import reduce -heapify(a) -while len(a) > 1: -    a1, a2 = heappop(a), heappop(a) -    m = a2 % a1 -    heappush(a, a1) -    if m: -        heappush(a, m) -print((heappop(a))) +answer = reduce(gcd, a) +print(answer)