def main():
    f, s = list(map(int, input().split()))
    first = list(map(int, input().split()))
    second = list(map(int, input().split()))
    if min(first) == min(second):
        print(min(first))
        return 0
    dmin = int(str(min(first)) + str(min(second)) if min(first) < min(second) else str(min(second)) + str(min(first)))
    first.sort()
    second.sort()
    for i in range(len(first)):
        if first[i] in second and first[i] < dmin:
            print(first[i])
            return 0
    print(dmin)


if __name__ == '__main__':
    main()
