
a = []
b = []
o = []
n,m = map(int, input().split())
a =input().split()
b =input().split()
for i in range(len(a)):
    for j in range(len(b)):
        if a[i] == b[j]:
            o.append(a[i])
if o == []:
    x = int(min(a))
    y = int(min(b))
    if x > y :
        ans = y * 10 + x
    elif x < y:
        ans = x * 10 + y
    print(ans)
else:
    ans = min(o)
    print(ans)
