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



D = list(map(int,input().split()))

OK = []

for i in range(10):

  if i not in D:

    OK.append(str(i))

#print(OK)

sn = str(N)

l = len(sn)



ans = N*1

Flag = 0

while Flag == 0:

  sans = str(ans)

  if all(sans[i] in OK for i in range(len(sans))):

    Flag = 1

  else:

    ans += 1

print(ans)

      

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

A = set(map(int,input().split()))

#A = set(A)

ok = []

for i in range(10):

  if i not in A:

    ok.append(i)

#print(ok)

while True:

  nstr = str(N)

  nstr = list(nstr)

  #print(nstr)

  Flag = True

  for x in nstr:

    x = int(x)

    if x in A:

      Flag = False

      break

  #print(Flag)

  if Flag:

    print(N)

    exit()

  else:

    N += 1

      
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
OK = []
for i in range(10):
    if i not in D:
        OK.append(str(i))
# print(OK)
sn = str(N)
l = len(sn)
ans = N * 1
Flag = 0
while Flag == 0:
    sans = str(ans)
    if all(sans[i] in OK for i in range(len(sans))):
        Flag = 1
    else:
        ans += 1
print(ans)

N, K = list(map(int, input().split()))
A = set(map(int, input().split()))
# A = set(A)
ok = []
for i in range(10):
    if i not in A:
        ok.append(i)
# print(ok)
while True:
    nstr = str(N)
    nstr = list(nstr)
    # print(nstr)
    Flag = True
    for x in nstr:
        x = int(x)
        if x in A:
            Flag = False
            break
    # print(Flag)
    if Flag:
        print(N)
        exit()
    else:
        N += 1

-D = list(map(int, input().split())) -OK = [] +A = set(map(int, input().split())) +# A = set(A) +ok = [] -    if i not in D: -        OK.append(str(i)) -# print(OK) -sn = str(N) -l = len(sn) -ans = N * 1 -Flag = 0 -while Flag == 0: -    sans = str(ans) -    if all(sans[i] in OK for i in range(len(sans))): -        Flag = 1 +    if i not in A: +        ok.append(i) +# print(ok) +while True: +    nstr = str(N) +    nstr = list(nstr) +    # print(nstr) +    Flag = True +    for x in nstr: +        x = int(x) +        if x in A: +            Flag = False +            break +    # print(Flag) +    if Flag: +        print(N) +        exit() -        ans += 1 -print(ans) +        N += 1