input()
a = [int(k) for k in input().split(' ') if k]
b = [int(k) for k in input().split(' ') if k]
result = 99999999
for f in range(len(a)):
    for s in range(len(b)):
        c = sorted([a[f], b[s]])
        if c[0] == c[1]:
            c[0] = 0
        v = c[0] * 10 + c[1]
        if v < result:
            result = v
print(result)
