n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
if min(a) in b:
    print(min(a))
elif min(b) in a:
    print(min(b))
else:
    if min(a) != 0 and min(b) != 0:
        if min(a) < min(b):
            print(min(a), min(b), sep='')
        elif min(a) > min(b):
            print(min(b), min(a), sep='')
    else:
        if min(a) == 0:
            if a[1] > min(b):
                print(min(b), 0, sep='')
            else:
                print(a[1], min(b), sep='')
        elif min(b) == 0:
            if b[1] > min(a):
                print(min(a), 0, sep='')
            else:
                print(b[1], min(a), sep='')
