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

a = map(int, raw_input().split())
b = map(int, raw_input().split())

a.sort()
b.sort()

i = 0
j = 0
flag = False
while i < n-1 and j < m-1:
    while i < n-1 and a[i] < b[j]: i += 1
    while j < m-1 and b[j] < a[i]: j += 1
    if a[i] == b[j]:
        print a[i]
        flag = True
        break
if not flag: print "%d%d" %(min(a[0], b[0]), max(a[0], b[0]))