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()
i = 0
j = 0
while  i < len(a) and j < len(b) and a[i] != b[j]:
    if a[i] < b[j]:
        i += 1
    else:
        j += 1
if i >= len(a) or j >= len(b):
    print(min(a[0], b[0]) * 10 + max(a[0], b[0]))
else:
    print(a[i])