import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split() 
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))

#--------------------------------WhiteHat010--------------------------------#
n,m = get_int_list()
lst1 = get_int_list()
lst2 = get_int_list()
l1 = min(lst1)
l2 = min(lst2)


lst = []
for i in lst1:
    for j in lst2:
        if i == j:
            lst.append(i)

if len(lst) != 0:
    print(min(lst))
elif l1 < l2:
    print(l1*10 + l2)
else:
    print(l2*10 + l1)