n, m = input().split()
n = int(n)
m = int(m)
c = [None]*n*m
a = [None]*10
b = [None]*10
a = input().split()
b = input().split()
k = 0
for i in range(0,len(a)):
      for j in range(0,len(b)):
            if a[i]!=b[i]:
                  c[k] = int(a[i]+b[j])
                  k+=1
            else:
                  c[k] = a[i]
                  k+=1
print(min(c))
