[m, n] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sa = set()
sb = set()
for i in a:
    if i not in sa:
        sa.add(i)
for i in b:
    if i not in sb:
        sb.add(i)
if len(sa&sb):
    res = min(sa&sb)
else:
    a = min(sa)
    b = min(sb)
    res = min(a,b)*10 + max(a,b)
print(res)