def main():

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

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



 while True :

  flg=0

  

  for i in range(0,len(str(num[0]))):

   stnum=str(num[0])

   if int(stnum[i]) in bad:

    flg=1

    break

   

  if flg==1:

   num[0]+=1

   continue

  else:

   break

  

 print((num[0]))



main()
def main():

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

 bad = list(map(str,input().split()))



 while True :

  flg=0

  

  for i in range(0,len(str(num[0]))):

   stnum=str(num[0])

   if stnum[i] in bad:

    flg=1

    break

   

  if flg==1:

   num[0]+=1

   continue

  else:

   break

  

 print((num[0]))



main()
def main():
    num = list(map(int, input().split()))
    bad = list(map(int, input().split()))
    while True:
        flg = 0
        for i in range(0, len(str(num[0]))):
            stnum = str(num[0])
            if int(stnum[i]) in bad:
                flg = 1
                break
        if flg == 1:
            num[0] += 1
            continue
        else:
            break
    print((num[0]))


main()

def main():
    num = list(map(int, input().split()))
    bad = list(map(str, input().split()))
    while True:
        flg = 0
        for i in range(0, len(str(num[0]))):
            stnum = str(num[0])
            if stnum[i] in bad:
                flg = 1
                break
        if flg == 1:
            num[0] += 1
            continue
        else:
            break
    print((num[0]))


main()

-    bad = list(map(int, input().split())) +    bad = list(map(str, input().split())) -            if int(stnum[i]) in bad: +            if stnum[i] in bad: