n, m = list(map(int, input().split(' ')))
narr = list(map(int, input().split(' ')))
marr = list(map(int, input().split(' ')))


ndic = {1: 0, 2: 0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0}
mdic = {1: 0, 2: 0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0}
for i in narr:
    ndic[i] = i
for i in marr:
    mdic[i] = i

def check():
    for i in range(1, 10):
        if ndic[i] == mdic[i] and ndic[i] != 0:
            return ndic[i]
    for i in range(1, 10):
        if ndic[i] != 0:
            for j in range(1, 10):
                if mdic[j] != 0:
                    if ndic[i] > mdic[j]:
                        return mdic[j] * 10 + ndic[i]
                    else:
                        return ndic[i] * 10 + mdic[j]

print(check())