def main():
    input()
    first_list = [int(_) for _ in input().split()]
    second_list = [int(_) for _ in input().split()]

    try:
        x = next(i for i in range(1, 10) if i in first_list and i in second_list)
        print(x)
    except StopIteration:
        a = min(first_list)
        b = min(second_list)

        print((a * 10 + b) if a <= b else (b * 10 + a))


if __name__ == '__main__':
    main()
