# F - Search for Pretty Integers 

a,b = input().split()
list1,list2 = input().split(),input().split()
for i in range(10):
    i = str(i)
    if i in list1 and i in list2:
        print(i)
        exit(0)
for i in range(10,100):
    i = str(i)
    if (i[0] in list1 and i[1] in list2) or (i[1] in list1 and i[0] in list2):
        print(i)
        exit(0)
    

