import itertools


def main():
    s,f = [int(v) for v in input().split()]
    d1 = input()
    d2 = input()
    for i in range(1,1000):
        if any(v in str(i) for v in d1) and any(v in str(i) for v in d2):
            print(i)
            return


if __name__ == "__main__":
    main()
