a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
c = [int(s) for s in input().split()]
d = []
for i in range (a[0]):
    for j in range (a[1]):
        if (b[i] == c[j]):
            d.append(b[i])
if (len(d) != 0):
    minD = 10
    for i in range(len(d)):
        if (minD > d[i]):
            minD = (d[i])
    print(minD)
else:
    minB = 10
    for i in range(len(b)):
        if (minB > b[i]):
            minB = (b[i])
    minC = 10
    for i in range(len(c)):
        if (minC > c[i]):
            minC = (c[i])
    if (minB < minC):
        print(str(minB) + str(minC))
    else:
        print(str(minC) + str(minB))