Ksusha is a beginner coder. Today she starts studying arrays. She has array a_1, a_2, ..., a_{n}, consisting of n positive integers.

Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^5), showing how many numbers the array has. The next line contains integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the array elements.


-----Output-----

Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.

If there are multiple answers, you are allowed to print any of them.


-----Examples-----
Input
3
2 2 4

Output
2

Input
5
2 1 3 1 6

Output
1

Input
3
2 3 5

Output
-1

Source: codeforces | Difficulty: EASY
Tags: Number theory

Sorting

Complete search


Solutions:
def main():
	n = int(input())
	L = list(map(int, input().split()))
	setL = set(L)
	rep = -1
	for i in setL:
		for j in setL:
			if j % i != 0:
				rep = -1
				break
			else:
				rep = i
		if rep != -1:
			break
	print(rep)
main()


I = input
I()
a = list(map(int, I().split()))
x = min(a)
print([x, -1][any((i % x for i in a))])


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
sys.stdout.write = lambda s: buf.write(s.encode('ascii'))
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
n = int(input())
a = list(map(int, input().split()))
m = min(a)
for i in range(n):
	if a[i] % m != 0:
		print(-1)
		exit()
print(m)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
x = arr[0]
f = 0
for i in range(n):
	if arr[i] % x != 0:
		f = 1
if f == 1:
	print(-1)
else:
	print(x)


n = int(input())
arr = list(map(int, input().split()))
min_ = arr[0]
for i in range(1, n):
	min_ = min(min_, arr[i])
for ele in arr:
	if ele % min_ != 0:
		print(-1)
		break
else:
	print(min_)


input()
X = sorted(list(map(int, input().split())))
if X[0] == 1:
	print(1)
	exit()
for i in range(len(X)):
	if X[i] % X[0] != 0:
		print(-1)
		exit()
print(X[0])


n = int(input())
v = list(map(int, input().split()))
v.sort()
for x in v:
	if x % v[0] != 0:
		print(-1)
		return
print(v[0])


import math
total = input()
string = input()
number = string.split(' ')
list = []
for i in number:
	list.append(int(i))
is_done = False
min = min(list)
for i in list:
	if i % min != 0:
		print(-1)
		is_done = True
		break
if not is_done:
	print(min)


n = int(input())
a = list(map(int, input().split()))
m = min(a)
a.append(m)
for i in range(n + 1):
	if a[i] % m != 0:
		print(-1)
		break
	if i == n:
		print(m)


num = input()
list1 = list(map(int, input().split(' ')))
list1.sort()
isDivisable = list1[0]
for i in range(1, len(list1)):
	if list1[i] % list1[0] != 0:
		isDivisable = -1
		break
print(isDivisable)


import math
n = int(input())
arr = [int(i) for i in input().split()]
res = arr[0]
for i in range(len(arr)):
	res = math.gcd(res, arr[i])
if res in arr:
	print(res)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
k = min(l)
t = 0
for i in range(n):
	if l[i] % k == 0:
		t += 1
if t == n:
	print(k)
else:
	print(-1)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
n = get_int()
lst = get_int_list()
g = lst[0]
for i in range(1, n):
	g = math.gcd(g, lst[i])
if g in lst:
	print(g)
else:
	print(-1)


n = int(input())
set_ = set(list(map(int, input().split())))
setLen = len(set_)
minElement = min(set_)
for i in set_:
	if i % minElement != 0:
		print(-1)
		exit()
print(minElement)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	m_n = min(a)
	ans = m_n
	for i in range(n):
		if a[i] % m_n != 0:
			ans = -1
			break
	print(ans)
while TN != 0:
	solution()
	TN -= 1


n = int(input())
a = list(map(int, input().split()))
a.sort()
d = a[0]
yes = True
for i in a:
	if i % d != 0:
		yes = False
		break
print(d if yes else -1)


import sys, math, string, bisect
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
n = int(input())
l = L()
l.sort()
for i in range(n):
	if l[i] % l[0] != 0:
		print(-1)
		exit()
print(l[0])


input()
A = set(map(int, input().split()))
x = min(A)
print(-1 if any((a % x for a in A)) else x)


n = int(input())
l = sorted(list(map(int, input().split())))
a = l[0]
for i in range(n):
	if l[i] % a != 0:
		print(-1)
		break
else:
	print(a)


n = int(input())
l = list(map(int, input().split()))
f = min(l)
c = 0
if 1 in l:
	print('1')
	exit(0)
else:
	for i in range(n):
		if l[i] % f == 0:
			c += 1
if c == n:
	print(f)
else:
	print('-1')


a = sorted(map(int, [*open(0)][1].split()))
print([a[0], -1][any((x % a[0] for x in a))])


import sys
inputs = sys.stdin.readline
n = int(inputs())
a = list(map(int, inputs().split()))
f = False
if min(a) == 1:
	print(1)
else:
	z = min(a)
	for i in range(n):
		if a[i] % z != 0:
			print(-1)
			exit()
	else:
		print(min(a))


(n, t) = (int(input()), list(map(int, input().split())))
k = min(t)
print(-1 if any((i % k for i in t)) else k)


n = int(input())
arr = list(map(int, input().split()))
arr = list(set(arr))
arr.sort()
test = 0
ans = -1
for i in arr:
	j = 0
	while j < len(arr):
		if arr[j] % i != 0:
			test = 1
			break
		j = j + 1
	if test == 0:
		ans = i
		break
print(ans)


input()
line = list(map(int, input().split()))
line.sort()
for i in line:
	if i % line[0] != 0:
		print(-1)
		break
else:
	print(line[0])


n = int(input())
x = list(set(map(int, input().split())))
x = sorted(x)
flag = 1
ans = x[0]
for i in x:
	if i % ans:
		flag = 0
if flag == 0:
	print(-1)
else:
	print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
for i in l:
	if i % l[0] != 0:
		print('-1')
		exit()
print(l[0])


from math import gcd
n = int(input())
a = list(map(int, input().split()))
d = a[0]
e = set(a)
for i in range(1, n):
	d = gcd(d, a[i])
if d in e:
	print(d)
else:
	print(-1)


import math
(n, a) = (int(input()), list(map(int, input().split())))
if n == 1:
	print(a[0])
else:
	g = math.gcd(a[0], a[1])
	for i in range(2, n):
		g = math.gcd(g, a[i])
	for d in range(1, int(math.sqrt(g)) + 1):
		if g % d == 0:
			if d in a:
				print(d)
				break
			elif g // d in a:
				print(g // d)
				break
	else:
		print(-1)


c = 0
input()
l = sorted(map(int, input().split()))
for i in l:
	if i % l[0] != 0:
		c = 1
		break
print([-1, l[0]][c == 0])


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[0]
sum = 0
for i in a:
	if i % x == 0:
		sum = sum + 1
if sum == n:
	print(x)
else:
	print('-1')


n = int(input())
a = list(map(int, input().split()))
mn = min(a)
for i in a:
	if i % mn != 0:
		mn = -1
		break
print(mn)


n = int(input())
a = [int(i) for i in input().split()]
d = min(a)
e = 0
for i in range(0, len(a)):
	if a[i] % d == 0:
		e = e + 1
if e == len(a):
	print(d)
else:
	print(-1)


n = int(input())
ls = list(map(int, input().split()))
minimum = min(ls)
answer = True
for l in ls:
	if l % minimum != 0:
		answer = False
		break
if answer:
	print(minimum)
else:
	print(-1)


n = int(input())
set_ = set(list(map(int, input().split())))
setLen = len(set_)
for i in set_:
	co = 0
	for j in set_:
		if j % i != 0:
			break
		else:
			co += 1
	if co == setLen:
		print(i)
		exit()
print(-1)


from fractions import gcd
(n, a) = (int(input()), list(map(int, input().split())))
v = a[0]
for ai in a:
	v = gcd(v, ai)
print(v if v in a else -1)


n = int(input())
x = list(map(int, input().split(' ')))
Min = min(x)
for i in x:
	if i % Min != 0:
		print(-1)
		exit()
print(Min)


n = int(input())
numbers = [int(x) for x in input().split()]
mi = min(numbers)
for x in numbers:
	if x % mi != 0:
		print(-1)
		exit()
print(mi)


from sys import stdin
from math import gcd
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
ans = arr[0]
for x in arr:
	ans = gcd(ans, x)
flag = False
for x in arr:
	flag |= x == ans
if flag:
	print(ans)
else:
	print(-1)


n = int(input().strip())
a = input().strip().split(' ')
j = 0
for i in a:
	a[j] = int(i)
	j = j + 1
d = min(a)
div = True
for i in a:
	if i % d != 0:
		div = False
		break
if div:
	print(d)
else:
	print(-1)


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

def x(a, l):
	l.sort()
	for i in range(a):
		if l[i] % l[0] != 0:
			return -1
	else:
		return l[0]
print(x(a, l))


def main():
	n = int(input())
	array = [int(c) for c in input().split()]
	_min = min(array)
	for e in array:
		if e % _min != 0:
			print(-1)
			return
	else:
		print(_min)
		return
main()


n = int(input())
L = [int(x) for x in input().split()]
L.sort()
x = L[0]
f = 0
for i in L:
	if i % x != 0:
		f = 1
		break
if f == 0:
	print(x)
else:
	print(-1)


n = input()
a = map(int, input().split())
a = sorted(a)
v = a[0]
ok = True
for i in a:
	if i % v > 0:
		ok = False
		break
if ok:
	print(v)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
k = min(a)
for i in a:
	if i % k != 0:
		exit(print(-1))
print(k)


N = int(input())
x = [int(x) for x in input().split()]
a = min(x)
for item in x:
	if item % a == 0:
		ans = 1
	else:
		ans = -1
		break
if ans == 1:
	print(a)
else:
	print(-1)


(f, n, l) = (0, int(input()), sorted(map(int, input().split())))
for x in range(n):
	if l[x] % l[0] != 0:
		f = 1
		break
print([l[0], -1][f == 1])


n = int(input())
a = list(map(int, input().split()))
k = min(a)
y = 0
for i in range(n):
	if a[i] % k == 0:
		y += 1
if y == n:
	print(k)
else:
	print(-1)


x = int(input())
ve = list(map(int, input().split()))
mn = min((int(i) for i in ve))
for i in range(0, x):
	if ve[i] % mn != 0:
		print('-1')
		exit()
print(mn)


n = int(input())
a = list(map(int, input().split()))
a.sort()
min1 = min(a)
for i in a:
	if i % min1 != 0:
		print(-1)
		break
else:
	print(min1)


n = int(input())
l = [int(j) for j in input().split()]
l.sort()
t = l[0]
flag = 1
for i in l:
	if i % t != 0:
		flag = 0
		break
if flag:
	print(t)
else:
	print(-1)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def occur(l, x):
	for i in range(len(l)):
		if l[i] == x:
			return i

def solve():
	n = inp()
	l = li()
	a = l[0]
	for i in range(1, n):
		a = math.gcd(a, l[i])
	if a in l:
		pr(a)
	else:
		pr(-1)
for _ in range(1):
	solve()


def gcd(a, b):
	factor = a
	while b % factor != 0:
		temp = factor
		factor = b % factor
		b = temp
	return factor

def main():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	if n == 1:
		print(arr[0])
		return
	factor = gcd(arr[0], arr[1])
	found = 1 if factor in (arr[0], arr[1]) else 0
	count = 2
	while count < n:
		if factor != 1:
			cd = gcd(factor, arr[count])
			if cd != factor and cd != arr[count]:
				found = 0
			else:
				found = 1
			factor = cd
		elif arr[count] == 1:
			found = 1
			break
		count += 1
	if found:
		print(factor)
	else:
		print(-1)
main()


input()
a = list(map(int, input().split()))
b = min(a)
for i in a:
	if i % b:
		print(-1)
		break
else:
	print(b)


def gcd(a, b):
	if b > a:
		a = a + b
		b = a - b
		a = a - b
	if a % b == 0:
		return b
	return gcd(b, a % b)

def solve(A):
	n = len(A)
	P = [A[0]]
	S = [A[-1]] * (n + 1)
	for i in range(1, n):
		P.append(gcd(P[-1], A[i]))
	for i in range(n - 1, -1, -1):
		S[i] = gcd(S[i + 1], A[i])
	for i in range(n):
		if gcd(S[i], P[i]) == A[i]:
			return A[i]
	return -1
n = input()
A = list(map(int, input().strip().split()))
print(solve(A))


n = int(input())
a = list(map(int, input().split(' ')))
min = 10 ** 9 + 1
for i in range(len(a)):
	if a[i] < min:
		min = a[i]
for i in range(len(a)):
	if a[i] % min != 0:
		print(-1)
		quit()
print(min)


n = int(input())
l = [int(i) for i in input().split()]
from math import gcd
g = 0
for i in l:
	g = gcd(g, i)
if g in l:
	print(g)
else:
	print(-1)


from sys import stdin

def read():
	return map(int, stdin.readline().split())
read()
a = list(read())
x = min(a)
for y in a:
	if y % x != 0:
		x = -1
		break
print(x)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = True
m = a[0]
for i in range(1, n):
	if not a[i] % m:
		continue
	else:
		print('-1')
		exit()
print(m)


garbage = int(input())
l = list(map(int, input().rstrip().split(' ')))
m = min(l)
r = m
for i in l:
	if i % m != 0:
		r = -1
print(r)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
minn = min(arr)
c = 0
for i in range(0, n):
	if arr[i] % minn == 0:
		continue
	else:
		c = c + 1
if c == 0:
	print(minn)
else:
	print('-1')


def main():
	from math import gcd
	input()
	s = set(map(int, input().split()))
	x = a = s.pop()
	for b in s:
		a = gcd(a, b)
		if a == 1:
			break
	s.add(x)
	print(a if a in s else -1)

def __starting_point():
	main()
__starting_point()


from math import gcd

def ans(A):
	g = A[0]
	for a in A:
		g = gcd(g, a)
	if g in A:
		return g
	return -1
input()
A = input().split(' ')
A = list(map(int, A))
print(ans(A))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_numbers = int(input())
numbers = read_ints()
mins = min(numbers)
ans = mins
for i in numbers:
	if i % mins:
		ans = -1
		break
print(ans)


input()
X = list(map(int, input().split()))
MIN = min(X)
if MIN == 1:
	print(1)
	exit()
for i in range(len(X)):
	if X[i] % MIN != 0:
		print(-1)
		exit()
print(MIN)


a = int(input())
s = [int(x) for x in input().split()]
key = True
c = min(s)
for i in s:
	if i % c != 0:
		key = False
		print(-1)
		break
if key:
	print(c)


n = int(input())
arr = sorted([int(p) for p in input().split()])
num = arr[0]
for i in range(len(arr)):
	if arr[i] % num != 0:
		print(-1)
		exit()
print(num)


n = int(input())
arr = sorted(map(int, input().split()))
mn = arr[0]
divs = sum((1 for i in arr if i % mn == 0))
if divs == n:
	print(mn)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[0]
f = True
for i in range(1, n):
	if a[i] % x != 0:
		print('-1')
		f = False
		break
if f == True:
	print(x)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = a[0]
for i in range(1, n):
	if a[i] % ans != 0:
		ans = -1
		break
print(ans)


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def getfctrlist(a):
	F = [1, a]
	for i in range(2, int(a ** 0.5) + 1):
		if a % i == 0:
			if a // i == i:
				F.append(i)
			else:
				F.append(i)
				F.append(a // i)
	F.sort()
	return F
n = int(input())
A = list(map(int, input().split()))
a = A[0]
for i in range(1, n):
	a = gcd(a, A[i])
F = getfctrlist(a)
ans = -1
for i in A:
	if i in F:
		ans = i
		break
print(ans)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
n = iinput()
a = linput()
d = min(a)
for e in a:
	if e % d != 0:
		print(-1)
		break
else:
	print(d)


n = int(input())
a = [int(x) for x in input().split()]

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while True:
		if a % b == 0:
			return b
		b = a % b
		a = b
if n == 1:
	print(a[0])
	return
ans = max(a)
for i in range(1, n):
	temp = gcd(a[i], a[i - 1])
	if temp <= ans:
		ans = temp
	if ans == 1:
		break
for i in a:
	if i % ans != 0:
		print(-1)
		return
if ans in a:
	print(ans)
else:
	print(-1)


import sys
import math
n = int(sys.stdin.readline())
an = [int(x) for x in sys.stdin.readline().split()]
vmin = 1000000001
for i in an:
	if i < vmin:
		vmin = i
for i in an:
	if i % vmin != 0:
		print(-1)
		exit()
print(vmin)


from fractions import gcd
n = int(input())
a = input().split()
a = [int(i) for i in a]
g = a[0]
for i in a:
	g = gcd(i, g)
if g in a:
	print(g)
else:
	print(-1)


import math
n = int(input())
z = list(map(int, input().split()))
l = 0
for i in z:
	l = math.gcd(l, i)
if l not in z:
	print(-1)
else:
	print(l)


n = int(input())
m = sorted(list(map(int, input().split())))
for i in range(1, n):
	if m[i] % m[0] != 0:
		print(-1)
		exit()
print(m[0])


n = int(input())
li = list(map(int, input().strip().split()))
li.sort()
(a, first, c) = (set(li), li[0], 0)
for i in a:
	if i % first == 0:
		c += 1
if c == len(a):
	print(first)
else:
	print(-1)


n = int(input())
A = list(map(int, input().split()))
k = min(A)
p = 0
for i in range(n):
	if int(A[i]) % int(k) != 0:
		p = 1
		break
if p == 1:
	print(-1)
else:
	print(k)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
flag = 0
for i in range(1, n):
	if a[i] % a[0]:
		flag = 1
		break
if flag:
	print(-1)
else:
	print(a[0])


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
m = arr[0]
flag = 1
for i in range(1, n):
	if arr[i] % m != 0:
		print(-1)
		flag = 0
		break
if flag:
	print(m)


n = int(input())
l = list(map(int, input().split()))
mini = min(l)
for i in l:
	if i % mini != 0:
		print(-1)
		break
else:
	print(mini)


n = int(input())
a = list(map(int, input().split()))
c = min(a)
for r in a:
	if r % c != 0:
		print('-1')
		quit()
print(c)


n = int(input())
s = [int(i) for i in input().split()]
a = min(s)
c = True
for i in range(n):
	if s[i] % a != 0:
		c = False
		break
if c:
	print(a)
else:
	print(-1)


n = int(input())
mas = list(map(int, input().split()))
mas = sorted(mas)
rez = -1
if 1 in mas:
	rez = 1
else:
	divisor = mas[0]
	s = 0
	for e in mas:
		if e % divisor != 0:
			break
		s += 1
	if s == len(mas):
		rez = divisor
print(rez)


n = int(input())
l = list(map(int, input().strip().split()))
j = min(l)
for x in range(n):
	if l[x] % j != 0:
		print(-1)
		break
else:
	print(j)


fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from string import *
from itertools import *
from collections import *
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from collections import Counter as cc
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))

def take():
	input = open('input.txt', 'r')
	stdout = open('output.txt', 'w')
z()
arr = szzz()
g = arr[0]
for i in arr[1:]:
	g = gcd(g, i)
if arr[0] != g:
	print(-1)
	exit()
print(g)


n = int(input())
l = list(map(int, input().split()))
if 1 in l:
	print('1')
else:
	s = set(l)
	for i in s:
		for j in s:
			if j % i == 0:
				pass
			else:
				break
		else:
			print(i)
			break
	else:
		print('-1')


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = a[0]
for i in range(1, n):
	if a[i] % m != 0:
		m = -1
		break
print(m)


n = int(input())
data = list(map(int, input().split()))
small = min(data)
for x in data:
	if x % small != 0:
		print(-1)
		import sys
		return
print(small)


from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
x = min(a)
for i in a:
	if i % x > 0:
		print(-1)
		break
else:
	print(x)


def main():
	input()
	numbers = [int(_) for _ in input().split()]
	numbers.sort()
	if 1 == numbers[0]:
		print(1)
	else:
		no = False
		for number in numbers[1:]:
			if number % numbers[0] != 0:
				no = True
				break
		print(-1 if no else numbers[0])
main()


input()
(m, *a) = sorted(map(int, input().split()))
print((m, -1)[any((i % m for i in a))])


import math
n = int(input())
l = list(map(int, input().split()))
gc = l[0]
for i in range(1, n):
	gc = math.gcd(gc, l[i])
print(gc if gc in l else '-1')


n = int(input())
arr = list(map(int, input().split()))
x = min(arr)
for el in arr:
	if el % x != 0:
		print(-1)
		break
else:
	print(x)


n = input()
li = list(map(int, input().split()))
m = min(li)
for item in li:
	if item % m != 0:
		m = -1
		break
print(m)


input()
a = [int(x) for x in input().split()]
b = min(a)
print(-1 if any((x % b for x in a)) else b)


n = int(input())
a = list(map(int, input().split()))
a.sort()
t = a[0]
for x in a:
	if x % a[0] != 0:
		t = -1
print(t)


from math import gcd

def factors(n):
	res = set()
	for i in range(1, n + 1):
		if n % i == 0:
			res.add(i)
	return res

def main():
	n = int(input())
	array = [int(c) for c in input().split()]
	array_set = set(array)
	for e in array_set:
		for a in array_set:
			if a % e != 0:
				break
		else:
			print(e)
			return
	print(-1)
main()


import functools

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = functools.reduce(gcd, a)
	if ans not in a:
		print(-1)
	else:
		print(ans)

def __starting_point():
	main()
__starting_point()


from fractions import gcd

def findGcd(data):
	g = data[0]
	for i in range(len(data) - 1):
		g = gcd(g, data[i + 1])
	return g
n = int(input())
a = [int(i) for i in input().split()]
gc = findGcd(a)
if gc in a:
	print(gc)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
m = min(l)
s = -1
for i in l:
	if i % m != 0:
		s = abs(i)
		break
if s == -1:
	print(m)
else:
	print(-1)


def f():
	liste = list(map(int, input().split()))
	m = min(liste)
	if m == 1:
		return m
	else:
		for el in liste:
			if el % m != 0:
				return -1
		return m
input()
print(f())


from sys import stdin

def read():
	line = stdin.readline()
	if line == '':
		exit()
	return line

def main():
	while True:
		read()
		a = list(map(int, read().split()))
		x = min(a)
		for y in a:
			if y % x > 0:
				x = -1
				break
		print(x)
main()


a = int(input())
b = list(map(int, input().split()))
c = min(b)
d = 0
for x in b:
	if x % c == 0:
		d = 1
	else:
		d = 0
		print(-1)
		break
if d == 1:
	print(c)


n = int(input())
A = list(map(int, input().split()))
m = min(A)
for x in A:
	if x % m:
		print('-1')
		exit(0)
print(m)


import math
n = input()
s = list(map(int, input().split()))
a = 0
for x in s:
	a = math.gcd(a, x)
if a in s:
	print(a)
else:
	print(-1)


from collections import defaultdict, deque, Counter, OrderedDict
from math import gcd

def main():
	n = int(input())
	(g, d) = (0, set())
	for i in map(int, input().split()):
		if g == 0:
			g = i
		else:
			g = gcd(g, i)
		d.add(i)
	print(g if g in d else -1)
main()


n = int(input())
l = list(map(int, input().split()))
m = min(l)
flag = 1
for i in l:
	if i % m != 0:
		flag = 0
		print(-1)
		break
if flag == 1:
	print(m)


a = int(input())
array = list(map(int, input().split()))
array.sort()
count = 0
for i in array[1:]:
	if i % array[0] == 0:
		count += 1
		continue
	else:
		break
if count == len(array) - 1:
	print(array[0])
else:
	print(-1)


n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
ans = a[0]
for b in a:
	if b % a[0] != 0:
		ans = -1
		break
print(ans)


N = int(input())
S = list(map(int, input().split()))
d = min(S)
val = d
for s in S:
	if s % val != 0:
		val = -1
		break
print(val)


n = int(input())
L = list(map(int, input().split()))
a = min(L)
for i in range(len(L)):
	if L[i] % a:
		i -= 1
		break
if i < len(L) - 1:
	print(-1)
else:
	print(a)


from sys import stdin, stdout
from collections import Counter
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda : list(map(int, stdin.readline().split()))
ei = lambda : map(int, stdin.readline().split())
ip = lambda : int(stdin.readline().strip())
n = ip()
li = sorted(list(set(ai())))
n = len(li)
c = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if li[j] % li[i] != 0:
			break
		c += 1
	if c == n - 1:
		exit(print(li[i]))
print(-1)


n = int(input())
nums = [int(j) for j in input().split()]
m = min(nums)
output = m
for j in range(n):
	if nums[j] % m != 0:
		output = -1
		break
print(output)


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
n = inp()
a = inlist()
g = a[0]
for i in range(1, n):
	g = gcd(g, a[i])
if g in a:
	print(g)
else:
	print(-1)


n = int(input())
b = True
s = list(map(int, input().split()))
g = min(s)
for i in s:
	if i % g != 0:
		b = False
print(-1 if not b else g)


a = int(input())
t = list(map(int, input().split()))
t.sort()
if 1 in t:
	print(1)
else:
	s = t[0]
	u = 0
	for k in range(a):
		if t[k] % s == 0:
			pass
		else:
			print(-1)
			u += 1
			break
	if u == 0:
		print(s)


import sys
n = int(sys.stdin.readline())
ar = sys.stdin.readline().split()
ar = [int(x) for x in ar]
ar.sort()
mn = ar[0]
mx = ar[-1]
founded = True
last = mn
for i in range(1, len(ar)):
	if last != ar[i]:
		last = ar[i]
		if ar[i] % mn != 0:
			founded = False
			break
if founded:
	print(mn)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
(c, x) = (0, 0)
a.sort()
for i in range(n):
	if a[i] % a[0] != 0:
		x = 1
if x == 0:
	print(a[0])
if x == 1:
	print('-1')


a = int(input())
li = list(map(int, input().split()))
li.sort()
if li[0] == 1:
	print(1)
	exit()
for i in li[1:]:
	if i % li[0] != 0:
		print(-1)
		exit()
else:
	print(li[0])


n = int(input())
arr = list(map(int, input().split()))
minimum = min(arr)
ans = minimum
for i in set(arr):
	if i % minimum != 0:
		ans = -1
		break
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for x in range(len(l)):
	if l[x] % l[0] == 0:
		count += 1
if count == len(l):
	print(l[0])
else:
	print(-1)


n = int(input())
lis = input().split()
for i in range(len(lis)):
	lis[i] = int(lis[i])
m = min(lis)
check = 1
for i in range(len(lis)):
	if lis[i] % m != 0:
		check = 0
if check == 0:
	print(-1)
else:
	print(m)


def f():
	input()
	a = list(map(int, input().split(' ')))
	m = min(a)
	for i in a:
		if i % m != 0:
			print(-1)
			break
	else:
		print(m)
f()


def solve(a):
	a.sort()
	if a[0] == 1:
		return 1
	l = len(a)
	divisor = a[0]
	for i in range(l):
		if a[i] % divisor != 0:
			return -1
	return divisor
n = int(input())
a = list(map(int, input().strip().split()))
print(solve(a))


import math
import itertools as it
(n, a) = (int(input()), list(map(int, input().split())))
g = list(it.accumulate(a, math.gcd))[-1]
divs = set()
for d in range(1, int(math.sqrt(g)) + 1):
	if g % d == 0:
		divs = divs.union({d, g // d})
ans = divs.intersection(set(a))
print(-1 if len(ans) == 0 else ans.pop())


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
n = ii()
a = li()
mina = min(a)
for i in range(n):
	if a[i] % mina != 0:
		exit(print(-1))
print(mina)


n = int(input())
l = list(map(int, input().split()))
m = min(l)
for i in l:
	if i % m:
		print(-1)
		exit()
print(m)


import math
n = int(input())
L = list(map(int, input().split()))
x = 0
for i in L:
	x = math.gcd(x, i)
if x not in L:
	print(-1)
else:
	print(x)


n = int(input())
list = [int(i) for i in input().split()]
list.sort()
if list[0] == 1:
	print(1)
	exit()
for i in range(n):
	if list[i] % list[0] != 0:
		print('-1')
		exit()
print(list[0])


n = int(input())
a = sorted(list(map(int, input().split())))
if all([x % a[0] == 0 for x in a]):
	print(a[0])
else:
	print(-1)


n = int(input())
a = [int(i) for i in input().split()]
m = min(a)
f = 1
for i in a:
	if i % m != 0:
		print(-1)
		f = 0
		break
if f == 1:
	print(m)


input()
l = list(map(int, input().split()))
l.sort()
for i in range(1, len(l)):
	if l[i] % l[0] != 0:
		print(-1)
		raise SystemExit
print(l[0])


n = int(input())
l = list(map(int, input().split()))
a = min(l)
c = 0
for i in range(len(l)):
	if l[i] % a == 0:
		c += 1
if c == len(l):
	print(a)
else:
	print('-1')


n = int(input())
a = sorted(list(set([int(a) for a in input().split(' ')])))
found = True
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if a[j] % a[i] != 0:
			found = False
			break
	if found:
		print(a[i])
		break
if not found:
	print(-1)