n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
for i in a:
    if i in b:
        print(i)
        break
else:
    c = a[0]
    d = b[0]
    if c < d:
        print(c, d, sep='')
    else:
        print(d, c, sep='')