ha,hz = map(int,raw_input().split())
nn = map(int,raw_input().split())
mm = map(int,raw_input().split())
mi = max(mm)
b = False
bb = False
for i in range(ha):
    currmi = nn[i]
    bb = False
    for j in range(hz):
        if nn[i]==mm[j]:
            currmi = nn[i]
            b = True
            bb = True
            break
    if currmi<mi and bb:
        mi = currmi
if b:
    print mi
else:
    nn = sorted(nn)
    mm = sorted(mm)
    x = min(nn[0],mm[0])
    y = max(nn[0],mm[0])
    z = x*10+y
    print z
