n, m = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
beautiful = 0
for i in l1:
    if i in l2:
        beautiful = i
        break
if beautiful == 0:
    if l1[0] < l2[0]:
        beautiful = (l1[0] * 10) + l2[0]
    if l1[0] > l2[0]:
        beautiful = (l2[0] * 10) + l1[0]
    if l2[0] == l1[0]:
        beautiful = l1[0]

print(beautiful)