import sys
a,b=map(int,input().split())
m=list(map(int,input().split()))
n=list(map(int,input().split()))
for i in range(1,10):
    if i in m and i in n:
        print(i)
        exit(0)
x=min(m)
y=min(n)
sys.stdout.write("%d%d"%(min(x,y),max(x,y)))