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()
mx = 10**10
ans = [10**10,10**10]

for i in range(n):
    for j in range(m):
        if lst1[i] == lst2[j]:
            mx = min(mx,lst1[i])
        ans[0] = min(ans[0],lst1[i])
        ans[1] = min(ans[1],lst2[j])

if mx != 10**10:
    print(mx)
else:
    ans.sort()
    print(ans[0]*10+ans[1])
