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()
for i in range(min(m,n)):
    if b[i] == a[i]:
        print(b[i])
        sys.exit()
print(min(a[0],b[0]),end=""),print(max(b[0],a[0]))