n,k=list(map(int,input().split()))

d=set(input().split())

a=[]

for i in range(n,10*n):

    if not set(str(i))&set(d):

        print(i)

        exit()
n,k=list(map(int,input().split()))

d=set(input().split())

for i in range(n,10*n):

    if not set(str(i))&d:

        print(i)

        exit()

n, k = list(map(int, input().split()))
d = set(input().split())
a = []
for i in range(n, 10 * n):
    if not set(str(i)) & set(d):
        print(i)
        exit()

n, k = list(map(int, input().split()))
d = set(input().split())
for i in range(n, 10 * n):
    if not set(str(i)) & d:
        print(i)
        exit()

-a = [] -    if not set(str(i)) & set(d): +    if not set(str(i)) & d: