N,K = list(map(int,input().split()))

D = list(input().split())



while True:

  f = True

  for s in str(N):

    if s in D:

      f = False

  if f:

    print((str(N)))

    break

  else:

    N+=1
N,K = list(map(int,input().split()))

D = set(input().split())



while len(set(str(N))&D)>0:

  N+=1



print(N)
N, K = list(map(int, input().split()))
D = list(input().split())
while True:
    f = True
    for s in str(N):
        if s in D:
            f = False
    if f:
        print((str(N)))
        break
    else:
        N += 1

N, K = list(map(int, input().split()))
D = set(input().split())
while len(set(str(N)) & D) > 0:
    N += 1
print(N)

-D = list(input().split()) -while True: -    f = True -    for s in str(N): -        if s in D: -            f = False -    if f: -        print((str(N))) -        break -    else: -        N += 1 +D = set(input().split()) +while len(set(str(N)) & D) > 0: +    N += 1 +print(N)