x,y = input().split()

x = int(x)
y = int(y)

o = list(map(int, input().split()))
p = list(map(int, input().split()))

o.sort()
p.sort()

a = len(o)
b = len(p)

i = 0
j = 0

f = []

while(i < a):
    while(j < b):
        if(o[i] == p[j]):
            f.append(o[i])
        j = j+1
    i = i+1
    j = 0

if(len(f)>0):
    print(f[0])

elif((o[0] > p[0]) and len(f) == 0):
    e = (p[0] * 10)+o[0]
    print(e)

elif((o[0] < p[0]) and len(f) == 0):
    e = (o[0] * 10)+ p[0]
    print(e)
