s = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
a.sort()
b.sort()
l = 1
for i in range(len(a)):
    for j in range(len(b)):
        if a[i] == b[j]:
            l = 0
            print(a[i])
            break
    if l == 0:
        break
if l == 1:
    print('{}{}'.format(min(b[0], a[0]), max(b[0], a[0])))