import sys
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

heapify(a)

while len(a) != 1:
    f = heappop(a)
    s = heappop(a)
    s %= f
    if s != 0:
        heappush(a, s)
    heappush(a, f)

print(heappop(a)) import sys sys from heapq import heapify, heappop, heappush sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split heapify(a) heapify a while len(a) != 1:
    f = heappop(a)
    s = heappop(a)
    s %= f
    if s != 0:
        heappush(a, s)
    heappush(a, f) len(a) != 1 len(a) len a 1 f = heappop(a) f heappop(a) heappop a s = heappop(a) s heappop(a) heappop a s %= f s f if s != 0:
        heappush(a, s)
     s != 0 s 0 heappush(a, s) heappush a s heappush(a, f) heappush a f print(heappop(a)) print heappop(a) heappop a input = sys.stdin.readline sys.stdin.readline input s %= f f s f = heappop(a) heappop(a) f n = int(input()) int(input()) n a = list(map(int, input().split())) list(map(int, input().split())) a s = heappop(a) heappop(a) s
import sys
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

heapify(a)

while len(a) != 1:
    f = heappop(a)
    s = heappop(a)
    s %= f
    if s != 0:
        heappush(a, s)
    heappush(a, f)

print(heappop(a))
