from sys import stdin
lines = stdin.readlines()
n = lines[0].split()[0]
m = lines[0].split()[1]
a1 = map(int,lines[1].split())
a2 = map(int,lines[2].split())
temp = True
c1 = min(a1)
c2 = min(a2)
if c1 == c2:
    print c1
    temp = False
c3 = min(c1,c2)
c4 = max(c1,c2)
if c3 == 0 and temp == True:
    print int(str(c4)+str(c3))
if c3 != 0 and temp == True:
    print int(str(c3)+str(c4))