from sys import stdin, stdout 

N,M = stdin.readline().split()
n = map(int,stdin.readline().strip().split())
m = map(int,stdin.readline().strip().split())
n = min(n)
m = min(m)

a = min(m,n)
b = max(m,n)

if a == b:
	stdout.write(str(a)+'\n')
else:
	stdout.write(str(a)+str(b)+'\n')
	
