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

print(beautiful)