n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
#print(a)
#print(b)
ma=1000
for i in range(n):
    #print("1st")
    if(a[i] in b):
        
        ma=a[i]
        break




print(min(int(str(a[0]) + str(b[0])),ma))