n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = sorted(a)
b = sorted(b)
for i in a:
    for j in b:
        if i==j:
            print(str(i))
            exit()
print(str(a[0])+str(b[0]))