def main():
    intergers = []
    n = []
    m = []

    while not intergers:
        imp = raw_input()
        intergers = imp.split(" ")
        intergers = [int(num) for num in intergers]

        if (len(intergers) != 2) or (not (0 < intergers[0] <= 9)) or (not (0 < intergers[1] <= 9)):
            intergers = []

    while not n:
        imp = raw_input()
        n = imp.split(" ")
        n = [int(num) for num in n]

        if (len(n) != intergers[0]) or (max(n) > 9) or (min(n) < 1):
            n = []

    while not m:
        imp = raw_input()
        m = imp.split(" ")
        m = [int(num) for num in m]

        if (len(m) != intergers[1]) or (max(m) > 9) or (min(m) < 1):
            m = []

    cnd = 0

    for x in range(0, intergers[0]):
        if n[x] in m and n[x] != min(n) and n[x] != min(m):
            cnd = n[x]
            
    for x in range(0, intergers[1]):
        if m[x] in n and m[x] != min(n) and m[x] != min(m):
            cnd = m[x]

    if (cnd):
        print (cnd)
    elif min(n) == min(m):
        print (min(n))
    elif min(n) in m and min(m) in n:
        if min(n) < min(m):
            print (min(n))
        else:
            print (min(m))
    elif min(n) in m:
        print (min(n))
    elif min(m) in n:
        print (min(m))
    elif min(n) < min(m):
        print (str(min(n)) + str(min(m)))
    else:
        print (str(min(m)) + str(min(n)))

main()