def pretty_integer(first, second):
    pretty_integer = []
    first.sort()
    second.sort()
    for i in range(len(first)):
        if first[i] in second:
            return first[i]
        else:
            for j in range(len(second)):
                pretty_integer.append(first[i]+second[j])
                pretty_integer.append(second[j]+first[i])
    return min(pretty_integer)


input = map(int, raw_input().split())

first_list = map(str, raw_input().split())
second_list = map(str, raw_input().split())

print(pretty_integer(first_list, second_list))