n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
q = set()
w = set()
s = set()
a.sort()
b.sort()
for i in range(n):
    q.add(a[i])
for i in range(m):
    w.add(b[i])
for i in range(1, 10, 1):
    if i in q and i in w:
        s.add(i)
        c.append(i)
c.sort()
if len(c) > 0:
    print(c[0])
else:
    x = a[0]
    y = b[0]
    if x > y:
        x, y = y, x
    print(str(x) + str(y))
