n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = a + b; c = sorted(list(set(c)));
for i in range(len(c)):
    if c[i] in a and c[i] in b: print(c[i]);exit()
d = min(a); e = min(b)
print(min(d,e),end = ""); print(max(d,e))
