input()

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

a.sort()
b.sort()
minimum = 10

for i in a:
  if i in b and i < minimum:
    minimum = i
if minimum != 10:
  print(minimum)
else:
  print(str(min(a[0], b[0]))+str(max(a[0], b[0])))
