n, m = map(int, input().split())
o = input().split()
d = input().split()
o.sort()
d.sort()
num = 0
for i in range(0, 10):
    if o.count(str(i)) == d.count(str(i)) and o.count(str(i)) != 0:
        num = i
        break
if num == 0:
    num = min(o[0], d[0]) + max(o[0], d[0])
print(num)