a,b=map(int,input().split())
s=input().split()
s1=input().split()
s=sorted(s)
s1=sorted(s1)
S=[]
for i in range(a):
    if s[i] in s1:
        S.append(s[i])
if len(S)!=0:
    print(min(S))
else:
    if s1[0]>s[0]:
        print(s[0],s1[0],sep='')
    else:
        print(s1[0],s[0],sep='')

