n,m=(int(x) for x in input().split())
a1=[int(x) for x in input().split()]
a2=[int(x) for x in input().split()]
mn1=min(a1);
mn2=min(a2);
if(mn1==mn2):
    print(mn1);
else:
    print(min(mn1,mn2),max(mn1,mn2),sep='')
