n,m = map(int, input().split())
a = list(map(int,input().split()))
a1 = list(map(int,input().split()))
b = min(a)
c = min(a1)
d = 10**10
for i in range(n):
    for j in range(m):
        if a[i] == a1[j] and a[i]<d:
            d = a[i]
if d!=10**10:
    print(d)

else:
    print(min(b,c),end = "")
    print(max(b,c))