def inp(s,j):
    s = ' ' + s
    it = ''
    k = 0
    for i in s:
        if i == ' ':
            k += 1
        if j == k and not i == ' ':
            it += i
    return int(it)
s = input()
n = inp(s,1)
m = inp(s,2)
a = list()
b = list()
s = input()
k = 0
Min1 = 10
Min2 = 10
Min = 10
for i in range(n):
    k += 1
    c = inp(s,k)
    a.append(c)
    if k == 1:
        Min1 = c
    if Min1 > c:
        Min1 = c
s = input()
k = 0
for i in range(m):
    k += 1
    c = inp(s,k)
    b.append(c)
    if k == 1:
        Min2 = c
    if Min2 > c:
        Min2 = c
k = 0
for i in a:
    for j in b:
        if (i == j):
            if k == 0:
                k += 1
                Min = i
            if Min > i:
                Min = i
if Min < 10:
    print(Min)
else:
    print(min(Min1,Min2)*10+max(Min1,Min2))
