n, m = input().split()
n = input().split()
m = input().split()
a = []
for i in n:
    for j in m:
        if i == j:
            a.append(int(i))
        else:
            a.append(int(i+j))
            a.append(int(j+i))
print(min(a))