n , m =list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y = min(a), min(b)
a.sort()
b.sort()
if (len(a) >= len(b)):
    for i in range(len(b)):
        if (b[i] in a):
            print(b[i])
            break
    else:
        if (x > y):
            print(str(y) + str(x))
        else:
            print(str(x) + str(y)) 
else:
    for i in range(len(a)):
        if (a[i] in b):
            print(a[i])
            break
    else:
        if (x > y):
            print(str(y) + str(x))
        else:
            print(str(x) + str(y))