n , m = map ( int , input (). split ())
l = list ( map ( int , input (). split ()))
p = list ( map ( int , input (). split ()))
l.sort()
p.sort()
def algo(l,p):
    for i in l:
        if i in p:
            return i
    t = min ( l )
    s = min ( p )
    x = ( 10 * t ) + s
    y = ( 10 * s ) + t
    return min(x,y)


print(algo(l,p))    