n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = 10

for i in a:
    if (i in b)and(i < c):
        c = i
for i in b:
    if (i in a)and(i < c):
        c = i
if c == 10:
    a_min = min(a)
    b_min = min(b)
    print(min(a_min, b_min), max(a_min, b_min), sep="")
else:
    print(c)