n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

flag1 = False
flag2 = False
flag3 = False

r1 = 11125
r2 = ""

for i in range(10):
    if i in a and i in b and not flag3:
        r1 = i
        flag3 = True
    if i in a and not flag1:
        r2 += str(i)
        flag1 = True
    if i in b and not flag2:
        r2 += str(i)
        flag2 = True
if int(r2) < r1:
    print(r2)
else:
    print(r1)
