n,m = map(int, input().split())
line1 = list(map(int,input().split()))
line2=  list(map(int,input().split()))
a = min(line1)
b = min(line2)
answer= []

for i in range(n):
    if line1[i] in line2:
        answer.append(line1[i])

for i in range(m):
    if line2[i] in line1:
        answer.append(line2[i])
if answer != []:
    print(min(answer))
else:    
    if a == 0 or b == 0:
        print(max(a,b),min(a,b),sep ='')
    else:
        print(min(a,b),max(a,b),sep='')