a,b=input().split()
c=[int(i) for i in input().split()]
d=[int(i) for i in input().split()]
e=[]
a=min(c)
b=min(d)
for i in c:
    if d.count(i)>0:
        e.append(i)
for i in d:
    if c.count(i)>0:
        e.append(i)       
if len(e)>0:
    s=min(e)
else:    
    if a!=b:
        s=str(min(a,b))+str(max(a,b))
    else:
        s=str(a)
print(s)
