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