import math
import re


def ria():
    return [int(i) for i in input().split()]


def ri():
    return int(input())


def rfa():
    return [float(i) for i in input().split()]


n, m = ria()
ar1 = ria()
ar2 = ria()

kek = ([min(ar1), min(ar2)])
ar3=sorted(ar1)
for i in ar3:
    if i in ar2:
        print(i)
        exit(0)


if min(kek) != max(kek):
    print(str(min(kek)) + str(max(kek)))
else:
    print(kek[0])
