n, m = map(int, input().split())
a, b = sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))
ans = []
p = a if len(a) > len(b) else b
q = b if len(b) < len(a) else a
for i in range(len(p)):
    if p[i] in q:
        ans.append(p[i])
if len(ans) != 0:
    print(min(ans))
else:
    print(str(min(p[0], q[0])) + str(max(p[0], q[0])))