n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
indicator = True
y = [0 for i in range(10)]
for i in range(n):
	y[a[i]] += 1
for j in range(m):
	if y[b[j]] != 0:
		print(b[j])
		indicator = False
		break
if indicator:
	q = ""
	x = min(a[0], b[0])
	y = max(a[0], b[0])
	q += str(x)
	q += str(y)
	print(q)

