n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
a1 = set(a)
b1 = set(b)
k = 0
for i in range(1, 10):
    if i in a1 and i in b1:
        k = i
        break

if k == 0 :
    k = int(str(min(a[0], b[0])) + str(max(a[0], b[0])))
    print(k)
else: print(k)