n,m = input().split()
n = int(n)
m = int(m)
q = list(map(int,input().split()))
w = list(map(int,input().split()))
i = 0
while (i<len(q)):
    if (q[i]<1):
        del q[i]
    else:
        i += 1
i = 0
while (i<len(w)):
    if (w[i]<1):
        del w[i]
    else:
        i += 1
q.sort()
w.sort()
ask = -1
for i in q:
    if (i in w):
        ask = i
        break
if (ask==-1):
    ask = int(str(min(q[0],w[0]))+str(max(q[0],w[0])))
print(ask)
