n, m = map(int, input().split())


a = input().split()
a = list(map(int, a))
a.sort()

b = input().split()
b = list(map(int, b))
b.sort()

present = 0
for el in a:
    if el in b:
        present += 1
        print(el)
        break
    else:
        continue

if present == 0:
    af = 0
    bf = 0

    number = ""
    if min(a[0], b[0]) == a[0] and a[0] != 0:
        number += str(a[0])
        af += 1
    elif min(a[0], b[0]) == a[0] and a[0] == 0:
        number += str(b[0])
        bf += 1

    elif min(a[0], b[0]) == b[0] and b[0] != 0:
        number += str(b[0])
        bf += 1
    elif min(a[0], b[0]) == b[0] and b[0] == 0:
        af += 1
        number += str(a[0])

    if af == 1:
        number += str(b[0])

    elif bf == 1:
        number += str(a[0])

    print(int(number))


