a=str(input())
b=str(input())
c=str(input())
b=b.split(' ')
c=c.split(' ')
for i in range(len(b)):
    b[i] = int(b[i])
for i in range(len(c)):
    c[i] = int(c[i])
b.sort()
c.sort()
if b[0]==c[0]:
    print(b[0])
else:
    print(str(b[0])+str(c[0]))