
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()
    if(int(a[0]) < int(b[0])):
        print(a[0]+b[0])
    if(int(a[0]) > int(b[0])):
        print(b[0]+a[0])
    if(int(a[0]) == int(b[0])):
        print(a[0])
        
Main()
    
