import sys
n,m = map(int, input().split())
a,b= [], []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n>m:
    l = a
    s = b
else:
    l = b
    s = a
for i in range(min(m,n)):
    for p in range(max(m,n)):
        if s[i] == l[p]:
            print(s[i])
            sys.exit()
print(min(a[0],b[0]),end=""),print(max(b[0],a[0]))