a, b = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
m = min(arr)
n = min(brr)
if m == n:
    print(m)
else:
    if m in brr:
        print(m)
    elif n in arr:
        print(n)
    else:
        if m > n:
            x = n*10 + m
            for i in arr:
                if i in brr and i < x:
                    print(i)
                    break
            else:
                print(n, m, sep='')
        else:
            x = m*10 + n
            for i in arr:
                if i in brr and i < x:
                    print(i)
                    break
            else:
                print(n, m, sep='')
            print(m, n, sep='')