a,b = list(map(int,input().split()))
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))

l1.sort()
l2.sort()
if(l1[0] == l2[0]): print(l1[0])
else:
    print(str(l1[0])+str(l2[0]))