a, b = map(int, input().split())
c = input().split()
d = input().split()
res1 = [0] * 10
res2 = [0] * 10
for i in range (a):
    res1[int(c[i])] = 1
for i in range (b):
    res2[int(d[i])] = 1  
for i in range (10):
    if res1[i] == res2[i] and res1[i] == 1:
        print(i)
        exit(0)
min1 = 9
for i in range (a):
    if min1 > int(c[i]):
        min1 = int(c[i])
min2 = 9
for i in range (b):
    if min2 > int(d[i]):
        min2 = int(d[i])  
if min1 < min2:
    print(min1, end = '')
    print(min2)
else:
    print(min2, end = '')
    print(min1)