
def Main():

    fl=str(input())
    nm=fl.split(" ")
    sl=str(input())
    a = sl.split(" ")
    if(len(a) != int(nm[0])):
        print("Error!")
        return

    tl=str(input())
    b = tl.split(" ")
    if(len(b)!=int(nm[1])):
        print("Error!")
        return

    a.sort()
    b.sort()
    for s in a:
        if s in b:
            print(s)
            return
            
    if a[0]<b[0]:
        print(a[0]+b[0])
    else:
        print(b[0]+a[0])


Main()
