a,b=map(int,input().split())
s=input().split()
s1=input().split()
s=sorted(s)
s1=sorted(s1)
if s[0]==s1[0]:
    print(s[0])
else:
    if s1[0]>s[0]:
        print(s[0],s1[0],sep='')
    else:
        print(s1[0],s[0],sep='')
