a, b = map(int, input().split())
ls1 = list(map(int, input().split()))
ls2 = list(map(int, input().split()))
ls1.sort()
ls2.sort()
f = ls1[0]
s = ls2[0]
if(f == s):
    print(f)
else:
    if(s > f): s, f = f, s
    print(s, f, sep='')