n, m = map(int, raw_input().split())
l1 = map(int, raw_input().split())
l2 = map(int, raw_input().split())

s = set()
t = set()

for i in xrange(n):
    s.add(l1[i])

for i in xrange(m):
    t.add(l2[i])

s.intersection_update(t)

if(len(s) > 0):
    print(min(s))
else:
    aux1 = min(l1)
    aux2 = min(l2)
    print("%d%d" % (min(aux1, aux2), max(aux1, aux2)))