#
# Created by Polusummator on 24.10.2020
# --------- Little PyPy Squad ---------
# Verdict: 
#
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s1 = set(a)
s2 = set(b)
s3 = s1.intersection(s2)
if s3:
    print(min(s3))
else:
    print(min(min(s1), min(s2)), max(min(s1), min(s2)), sep='')
