n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

minn = 100

for i in range(n):
    for j in range(k):
        if a[i] == b[j]:
            if a[i] < minn:
                minn = a[i]
                
        elif int(str( min(a[i],b[j]) ) + str( max(a[i],b[j]) ))  < minn:
            minn = int(str(min(a[i],b[j])) + str(max(a[i],b[j])))
            
print(minn)