def readInts(): return map(int, input().split())

input()
a = list(readInts())
b = list(readInts())
for i in range(1,10):
  if ( i in a ) and ( i in b ):
    print(i)
    exit()

a = min(a)
b = min(b)
print ( min(a,b)*10 + max(a,b) )
