a,b=map(int,input().split())
s=input().split()
x=list(map(int,s))
s=input().split()
y=list(map(int,s))
o=10
for i in range(a):
    for j in range(b):
        if x[i]==y[j]:
            if x[i]<o:
                o=x[i]
x1=min(x)
y1=min(y)
if o<10:
    print(o)
else:
    print(min(y1,x1)*10+max(x1,y1))
