Problem:
 Score : 300 points    Problem Statement Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K .  She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).  However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.  Find the amount of money that she will hand to the cashier.      Constraints  1 ≦ N < 10000  1 ≦ K < 10  0 ≦ D_1 < D_2 < … < D_K≦9  \{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}         Input The input is given from Standard Input in the following format:  N  K  D_1  D_2 … D_K       Output Print the amount of money that Iroha will hand to the cashier.        Sample Input 1 1000 8
1 3 4 5 6 7 8 9      Sample Output 1 2000  She dislikes all digits except 0 and 2 .  The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2 , is 2000 .       Sample Input 2 9999 1
0      Sample Output 2 9999

Solution (Python):
N, K = map(int, input().split())
li_n = list(map(int, input().split()))
for i in range(N, 100000):
  if len(set(li_n)&set([int(y) for y in str(i)])) == 0:
    print(i)
    break

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
 
while True:
    l = list(str(N))
    for x in l:
        if x in D:
            N += 1
            break
    else:
        print(N)
        exit()

Solution (Python):
N,K = [int(i) for i in input().split()]


D = input().split()

D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,88889):
    if use >= set(str(i)):
        print(i)
        break

Solution (Python):
N,K = [int(i) for i in input().split()]


D = input().split()

D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,100*N):
    if use >= set(str(i)):
        print(i)
        break

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
x=list(range(1,100000)[::-1])
for i in d:
  a=[]
  for j in x:
    if i not in str(j):
      a.append(j)
  x=a
import bisect as bi
x=x[::-1]
print(x[bi.bisect_left(x,n)])

Solution (Python):
N, K = map(int, input().split())
D = set(map(int, input().split()))
safe = set(range(10)) - D

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if test(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y

answer = F(N)
print(answer)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())

while True:
    l = list(str(N))
    for x in l:
        if x in D:
            N += 1
            break
    else:
        print(N)
        exit()

Solution (Python):
n, k = map(int, input().split())
d = list(map(str, input().split()))

for i in range(n, 100001):
    flag = True
    for j in str(i):
        if j in d:
            flag = False

    if flag:
        print(i)
        exit()

Solution (Python):

from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, k = [int(item) for item in input().split()]
d = [item for item in input().split()]
for i in range(n, n+10**5):
    si = str(i)
    ok = True
    for item in d:
        if item in si:
            ok = False
            break
    if ok:
        print(i)
        exit()

Solution (Python):

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





def getMinimumOK():

    for i in range(0, 9):
        for j in range(1, K):
            if D[j - 1] == str(i):
                break
            else:
                return str(i)

def getFirstNG():


    for i in range(0, len(N)):
        for ng in D:
            if ng == N[i]:
                return i + 1

def isOK(number):

    strNumber = str(number)
    strlen = len(strNumber)
    for i in range(strlen):
        if strNumber[i] in D: 
            return False      
    return True

def makeUpperHalf(upperHalf_org):


    numUpper = int(upperHalf_org)
    while True:
        numUpper += 1
        if isOK(numUpper): 
            break
    return str(numUpper)

if isOK(int(N)): 
    print(N)     
else:
    minimumOK = getMinimumOK() 
    firstNG = getFirstNG()     

    upperHalf = N[:firstNG] 
    lowerHalf = N[firstNG:] 
    upper = makeUpperHalf(upperHalf)
    lower = minimumOK * len(lowerHalf) 
    print(upper + lower)

Solution (Python):
N,K = map(int,input().split())
D = list(map(str,input().split()))

for h in range(N,100001):
    c = True
    for e in str(h):
        if e in D:
            c = False
    if c:
        print(h)
        exit()

Solution (Python):
N, K = map(int, input().split())
DL = list(map(int, input().split()))
Dlist = [1,1,1,1,1,1,1,1,1,1]
for i in range(len(DL)):
  Dlist[DL[i]]=0

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))

flg = 0
flg2 = 0
while flg == 0:
	for i in range(len(str(n))):
		flg2 = 0
		if int(str(n)[i]) in d:
			flg2 = 1
			n += 1
			break
	if flg2 == 0:
		flg = 1
print (n)

Solution (Python):
n,k = map(int,input().split())
D = list(map(int,input().split()))

ans = n
while True:
    if any( [x in D for x in list(map(int,str(ans)))] ):
        ans += 1
    else:
        print(ans)
        break

Solution (Python):
min = list(map(int,input().split()))[0]
min = int(min)
l = list(map(int,input().split()))
while True:
  temp = min
  flag = True
  for i in range(len(str(min))):
    temp_ = temp % 10
    if temp_ in l:
      min += 1
      flag = False
      break
    else:
      temp //= 10
  if i == len(str(min))-1 and flag:
    break
print(min)

Solution (Python):
N,K = map(int,input().split())
Data = list(map(int,input().split()))

def check(n):
    while n > 0:
        if n % 10 in Data:
            return False
        n //= 10
    return True

while True:
    if check(N):
        break
    N += 1

print(N)

Solution (Python):
cnt=[0,1,2,3,4,5,6,7,8,9]
n,k=map(int,input().split())
d=list(map(int,input().split()))
tmp=[]
for i in range(k):
    cnt.remove(d[i])

def digit(x):
    xt=str(x)
    for i in range(len(xt)):
        if not int(xt[i]) in cnt:
            return  False
    return  True
t=n
while t>=n:
    if digit(t):
        print(t)
        exit()
    else:
        t+=1

Solution (Python):
total, k = map(int, input().split())
ds = list(input().split())

for i in range(total,total*10+2):
  for d in ds:
    if d in list(str(i)):
      break
  else:
    print(i)
    exit(0)

Solution (Python):
total, k = map(int, input().split())
ds = list(input().split())

ans = total
while True:
  flag = False
  for d in ds:
    if d in list(str(ans)):
      flag = True
  if flag:
    ans += 1
  else:
    print(ans)
    exit(0)

Solution (Python):
def examC():
    import bisect
    N, K = LI()
    D = list(map(str,input().split()))
    ansC = []
    for i in range(100001):
        cur = str(i)
        k = 1
        for s in cur:
            if s in D:
                k = 0
                break
        if k==1:
            ansC.append(i)

    k = bisect.bisect_left(ansC, N)
    ans = ansC[k]
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):


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

temp=[]
for i in range(10):
    if D.count(i)==0:
        temp.append(i)
D=temp[:]
preK=0
K=10-K

opt=D[:]
ans=10**18

for item in opt:
    if item>=N:
        ans=min(ans,item)

for t in range(5):
    for d in D:
        for i in range(preK,K):
            if opt[i]==0:
                pass
            else:
                num=int(str(opt[i])+str(d))
                if num>=N:
                    ans=min(ans,num)
                else:
                    opt.append(num)
    preK,K=K,len(opt)        
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline


N,K = map(int,input().split())
D = set(input().split())

for i in range(N,N*10+1):
    if not D&set(str(i)):
        break

print(i)

Solution (Python):
N,K=map(int,input().split())
D=sorted(list(map(int,input().split())))
ans=0
L=[i for i in range(10) if i not in D]

for i in range(N,10*N+1):
    I=[int(j) for j in list(str(i))]
    cnt=0
    
    for j in I:
        if j not in L:
            break
        else:
            cnt+=1
    if cnt==len(I):
        ans=i
        break

print(ans)

Solution (Python):
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n

Solution (Python):
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
'''
for i in range(9): 
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        if s_can_use[0] == 0:
'''
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n

Solution (Python):
n, k = map(int, input().split())
D = set(input().split())
use = set(map(str, range(10)))
use -= D

for num in range(n, 100*n):
    if use >= set(list(str(num))):
        print(num)
        exit()

Solution (Python):
n, k = map(int, input().split())
D = set(input().split())
use = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
use -= D
use = list(use)
l = len(str(n))

ans = use.copy()
prev = use.copy()
digit = 0
while digit <= l:
    temp = []
    for x in prev:
        for v in use:
            temp.append(x+v)
    ans += temp
    prev = temp
    digit += 1

ans = list(map(int, ans))
ans.sort()

for num in ans:
    if num >= n:
        print(num)
        break

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
while True:
    l = [int(x) for x in str(N)]
    for e in l:
        if e in D:
            N += 1
            break
    else:
        break
print(N)

Solution (Python):
n,k=map(int,input().split())
d=set(list(map(int,input().split())))

def checkIfOk(num):
  while True:
    if num%10 in d:
      return False
    else:
      num=num//10
    if num==0:
      return True

while True:
  if checkIfOk(n):
    print(n)
    break
  n+=1

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
ans = N - 1

while True:
  ans += 1
  str_ans = list(map(int, str(ans)))
  ans_len = len(str(ans))
  ans_check = 0
  for i in range(ans_len):
    if str_ans[i] not in D:
      ans_check += 1
  if ans_len == ans_check:
    print(ans)
    break

Solution (Python):
n,k = [int(i) for i in input().split()]
all_num = {'0','1','2','3','4','5','6','7','8','9'}
l = all_num - {i for i in input().split()}

for i in range(n,n*20):
    if not set(str(i)) - l:
        print(i)
        break

Solution (Python):
import itertools
N,K=map(int,input().split())
D=set(list(map(str,input().split())))
U=list({'0','1','2','3','4','5','6','7','8','9'}^D)
U.sort()

PRD1 = list(itertools.product(U, repeat=len(str(N))))
PRD2 = list(itertools.product(U, repeat=len(str(N))+1))

import sys
for i in range(len(PRD1)):
    T=int(''.join(PRD1[i]))
    if T>=N:
        print(T)
        sys.exit()

for i in PRD2:
    T=int(''.join(i))
    if T>=N:
        print(T)
        sys.exit()

Solution (Python):

N, K = map(int, input().split())
D = list(map(str, input().split()))
for tmp in range(N, 10*N+1):
    tmp_l = list(str(tmp))
    cnt = 0
    for t in tmp_l:
        if t in D:
            cnt += 1
    if cnt == 0 and int(tmp) >= N:
        print(tmp)
        exit()

Solution (Python):
ns,k = input().split()
nlist = set(input().split())
nslist = set(list(ns))
while nslist & nlist:
    ns = int(ns)+1
    ns = str(ns)
    nslist = set(list(ns))
print(ns)

Solution (Python):
N,K = map(int,input().split())
D = list(map(str,input().split()))

ans = 0

for j in range(N,10*N+1):
  f = True
  for k in D:
    if str(k) in str(j):
      f = False
      break
  if f:
    ans = j
    break
    
print(ans)

Solution (Python):
line=input().split()
N=int(line[0])
K=int(line[1])
D=input().rstrip().split()

for i in range(N,10*N+1):
 s=str(i)
 flag=True
 for x in D:
  if x in s:
   flag=False
   break

 if flag:
  print(s)
  break
 else:
  continue

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    Dk = lines[1].split()
    for i in range(N, 10 * N):
        for D in Dk:
            if D in str(i):
                break
        else:
            print(i)
            break
    return


main()

Solution (Python):
N,K=map(int,input().split())
D=input().split()
r=N
while True:
    if not any([c in D for c in str(r)]):
        break
    r+=1
print(r)

Solution (Python):

N,K = map(int, input().split())
D_set = set([int(e) for e in input().split()])

INF = 9999999999

OK_D = {0,1,2,3,4,5,6,7,8,9} - D_set

OK_D_list = list(OK_D)
OK_D_list.sort

ans = []
pay = 0

def dfs(pos,pay):
    
    
    
    
    
    if pos >= 5 or pay>=N:
        
        if pay>=N:
        
            ans.append(pay)
            return pay
        else:
            return INF
        
    
    
    for number in OK_D_list:
        
        dfs(pos+1 ,pay*10 + number) 
        
    

dfs(0,0)


print(min(ans))

Solution (Python):
import itertools
N,K = map(int,input().split())
D = list(map(int,input().split()))
A = []
for i in range(10):
    if i not in D:
        A.append(i)
cmin = 100000
k = len(str(N))
for i in range(k,6):
    for x in itertools.product(A,repeat=i):
        cnt = 0
        for j in range(i):
            cnt += x[j]*10**(i-1-j)
        if cnt>=N:
            cmin = min(cmin,cnt)
print(cmin)

Solution (Python):
import string
import sys

N,K=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in D]

def check(use,x):
    for i in str(x):
        if(int(i) not in use):
            return False
    return x

i=N-1
while True:
    i+=1
    x=check(use,i)
    if(x!=False):
        print(x)
        sys.exit()

Solution (Python):
"""
author : dokueki
1000 8
1 3 4 5 6 7 8 9
"""
def check(x,arr):
    c=0
    s = [int(i) for i in str(x)]
    for i in s:
        if i in arr:
            c+=1
    if c==len(s):
        return True
    return False


n, k = map(int, input().split())
a = list(map(int, input().split()))
use,f = [],0
for i in range(0, 10):
    if i not in a:
        use.append(i)

paid = [int(i) for i in str(n)]
for i in paid:
    if i in use:
        f+=1
if f==len(paid):
    print(n)
else:
    while True:
        n+=1
        if check(n,use)==True:
            print(n)
            break

Solution (Python):
N, K = map(int,input().split())
D = list(map(int,input().split()))
a = 10 
b = 10
c = 10
d = 10
e = 10
ans = 100000
for i in range(N,100000):
    if i >= 10000:
        a = i//10000
    if i >= 1000:
        b = (i//1000)%10
    if i >= 100:
        c = (i//100)%10
    if i >= 10:
        d = (i//10)%10
    e = i%10
    S = D.count(a) + D.count(b) + D.count(c) + D.count(d) + D.count(e)
    if S == 0:
        if ans > i:
            ans = i
print(ans)

Solution (Python):
n,k= map(int, input().split())
d= list(input().split())
for i in range(n,10*n+1):
    x=str(i)
    ans=True
    for j in range(len(x)):
        if x[j] in d:
            ans=False
    if ans:
        print(i)
        break

Solution (Python):
n,k= map(int, input().split())
d= list(input().split())
for i in range(n,10*n+1):
    x=str(i)
    ans=True
    for j in range(len(x)):
        if x[j] in d:
            ans=False
    if ans:
        print(i)
        break

Solution (Python):

import sys


def solve(N: int, K: int, D: "List[int]"):    
    while True:
        for d in D:
            strn=str(N)
            if str(d) in strn:
                break
        else:
            print(N)
            return 
        N+=1

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    D = [int(next(tokens)) for _ in range(K)]  
    solve(N, K, D)

if __name__ == '__main__':
    main()

Solution (Python):
  


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

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

pay = sum
while True:
  flag = 0;
  str_pay = str(pay)
  for i in str_pay:
    if int(i) in dis:
      flag = 1
      break
  if flag == 0:
    break
  else:
    pay = pay + 1
print(pay)

Solution (Python):
n, k = map(int, input().split())
d = list(input().split())

while 1:
    if all(dd not in str(n) for dd in d):
        print(n)
        break
    n = n+1

Solution (Python):
n, k = list(map(int,(input().split(' '))))
d = set(list(map(int,(input().split(' ')))))
l = set(list(range(0,10)))

like = l -d 



for i in range(n,100001):
  
  if like >= set(list(map(int,(str(i))))):
  
    
    break

print(i)

Solution (Python):
N,K=map(int,input().split())
D=list(input().split())

for i in range(N,10*N+1):
  s=str(i)
  flag=True
  for x in D:
    if x in s:
      flag=False
      break
  if flag:
    print(s)
    break
  else:
    continue

Solution (Python):

n,k=map(int,input().split())
lists=list(map(int,input().split()))
uselist=[]
for i in range(k):
    uselist.append(str(lists[i]))
flag=True
flag2=True
ans=str(n)
while flag2:
    for i in range(len(ans)):
        if ans[i] in uselist:

            flag=False
            break
        else:

            pass
    if flag:
        flag2=False
    else:
        flag=True
        ans=int(ans)
        ans+=1
        ans=str(ans)
print(ans)

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))

use_list = []
for i in range(10):
    if i not in d:
        use_list.append(str(i))

for a in use_list:
    if int(a) >= n:
        print(int(a))
        exit()

for a in use_list:
    for b in use_list:
        if int(a+b) >= n:
            print(int(a+b))
            exit()

for a in use_list:
    for b in use_list:
        for c in use_list:
            if int(a+b+c) >= n:
                print(int(a+b+c))
                exit()

for a in use_list:
    for b in use_list:
        for c in use_list:
            for d in use_list:
                if int(a+b+c+d) >= n:
                    print(int(a+b+c+d))
                    exit()

for a in use_list:
    for b in use_list:
        for c in use_list:
            for d in use_list:
                for e in use_list:
                    if int(a+b+c+d+e) >= n:
                        print(int(a+b+c+d+e))
                        exit()

Solution (Python):
tg = int(input().split(' ')[0])
target_int = set(list( str(tg) ))
deny_int= set(input().split(' '))

while target_int - deny_int != target_int:
  tg= tg+1
  target_int = set(list(str(tg)))

print(tg)

Solution (Python):
import sys
import bisect
all_flg = False
n, k = [int(i) for i in sys.stdin.readline().split()]
d_ls = [int(i) for i in sys.stdin.readline().split()]
candidate = [i for i in range(10) if i not in d_ls]
set_candidate = set(candidate)
len_cand = len(candidate)
last_ans = n
while True:
    ans = list(str(last_ans))
    flg = False
    flg_ls = [0 for i in range(len(str(n)))]
    for i, s in enumerate(str(last_ans)):
        s = int(s)
        res = bisect.bisect_left(candidate, s)
        if flg:
            ans[i] = str(candidate[0])
        else:
            if res >= len_cand:
                flg_ls[i] = 1
            ans[i] = str(candidate[res if res < len_cand else 0])
        if s not in set_candidate:
            flg = True
    ans = int("".join(ans))
    hoge = int("".join([str(i) for i in flg_ls]) + "0")
    ans += hoge
    if ans == last_ans:
        break
    last_ans = ans
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def isOk(n, D):
    while n > 0:
        if n % 10 in D:
            return False
        n //= 10
    return True


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ans = 0
    for i in range(N, 10**5):
        if isOk(i, D):
            print(i)
            return


if __name__ == '__main__':
    main()

Solution (Python):
n, k = map(int, input().split())
d = set(map(str, input().split()))
for i in range(n, 10*n):
    if len(d & set(str(i))) == 0:
        print(i)
        break

Solution (Python):
N, K = map(int, input().split())
D = set(list(map(int, input().split())))

for i in range(N, 100001):
    tmp = i
    while tmp > 0 and tmp % 10 not in D:
        tmp = tmp // 10
    if tmp == 0:
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
dis = input().split()
m = n
while True:
    m = str(m)
    for d in dis:
        if d in m:
            break
    else:
        print(m)
        exit()

    m = int(m) + 1

Solution (Python):
price, size = map(int, input().split())
dislikes = list(map(int, input().split()))
likes = list(set(range(10)) - set(dislikes))
digits = [int(digit) for digit in str(price)]
r_digits = list(reversed(digits))
res = []
for i in range(len(r_digits)):
    if r_digits[i] in likes:
        res.append(r_digits[i])
    elif max(likes) > r_digits[i]:
        res = [min(likes) for i in range(i)] + [min(x for x in likes if x > r_digits[i])]
    else:
        res = [min(likes) for i in range(i+1)]
        if i == len(r_digits)-1:
            res.append(min(x for x in likes if x > 0))
            
        else:
            r_digits[i+1] += 1

ans = "".join([str(num) for num in list(reversed(res))])
print(ans)

Solution (Python):
N, K = map(int, input().split())
d = list(map(int, input().split()))
a = []
for i in range(10):
    if d.count(i) == 0:
        a.append(i)
ans = []
def dfs(s):
    if int(s) >= N or len(s) > 6:
        return s
    for i in a:
        S = dfs(s + str(i))
        if int(S) >= N:
            ans.append(int(S))
    return s
    
dfs('0')
print(min(ans))

Solution (Python):
n,k = map(int,input().split())
nums =set(input().split())
i = n
while True:
    i = str(i)
    for num in nums:
        if num in i:
            break
    else:
        print(i)
        exit()
    
    i =int(i)+1

Solution (Python):
N, K = map(int, input().split())
D = [_ for _ in input().split()]

t = N
while 1:
    s = str(t)
    flg = True
    for i in range(len(s)):
        if s[i] in D:
            flg = False
    if flg:
        res = t
        break
    t += 1
print(res)

Solution (Python):
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] 
enableList = list(set(range(10)) - set(disabledList)) 
resultList = [] 
isTenOver = False
for char in reversed(list(str(val))):
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if targetInt in enableList:
    isTenOver = False
    resultList.append(str(targetInt))
    continue
  resultList = [str(min(enableList))] * len(resultList)
  if targetInt > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > targetInt, enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(reversed(resultList)))

Solution (Python):
N,K = map(int,input().split())
D = tuple(input().split())

for i in range(N,N*10):
  flag = True
  for d in str(i):
    if d in D:
      flag = False
      break
  if flag:
    print(i)
    exit()

Solution (Python):
N,K = map(int,input().split())
D = set(list(map(int,input().split())))
for i in range(N,10*N):
  ans = []
  ans += str(i)
  sA =set(map(int,ans))
  if sA&D == set():
    break

print(i)

Solution (Python):
n, k = map(int, input().split())
d = set(input().split())
num = n
while True:
    if len(set(list(str(num))) & d) == 0:
        print(num)
        break
    num += 1

Solution (Python):
p, _ = [int(x) for x in input().split(' ')]
v = set([str(x) for x in range(10)]) - set(input().split(' '))

for x in range(p, 100000):
  if all([s in v for s in str(x)]):
    print(x)
    break

Solution (Python):
n, k = map(int, input().split())
d = set(input().split())
for i in range(n, 10*n):
    if len(set(str(i)) & d) == 0:
        print(i)
        break

Solution (Python):


N, K = map(int, input().split())
D = set(input().split())

set_str_N = set(str(N))

while len(set_str_N & D) > 0:
    N = N + 1
    set_str_N = set(str(N))
    
print(N)

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
all_num = [i for i in range(10)]
not_d = list(set(all_num) - set(d))
not_d_str = [str(i) for i in not_d]

ans = []
for i in range(n, 10 * n):
    if set(list(str(i))).issubset(set(not_d_str)):
        print(i)
        exit()

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
all_num = [i for i in range(10)]
not_d = list(set(all_num) - set(d))
not_d_str = [str(i) for i in not_d]
ans = []
for i in range(n, 10 * n):
    if set(list(str(i))).issubset(set(not_d_str)) and i >= n:
        print(i)
        exit()

Solution (Python):
n,k = map(int,input().split())
d = list(map(int,input().split()))
nd = list()
for i in range(10):
    if i not in d:
        nd.append(i)
a = n

for i in range(10*n):
    if set([int(m) for m in list(str(a+i))]) == set(list(set([int(m) for m in list(str(a+i))]) & set(nd))):
        print(a+i)
        break

Solution (Python):

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

    
l=input().split()
def check(s): 
    for i in s: 
        if i in l: 
            return 0 
    return 1 
for x in range(n,10**9): 
    if check(str(x)):
        print(x)
        exit()

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for i in list(map(int, input().rstrip('\n').split())):
        d[i]
    for i in range(n, 10 ** 10):
        s = str(i)
        b = True
        for j in range(len(s)):
            if int(s[j]) in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()

Solution (Python):
n,k = map(int,input().split())
memo = list(map(int,input().split()))

d = []
for i in range(10):
    if not(i in memo):
        d.append(i)

N = n
flug = False
while(1):
    n_st = list(str(n))
    n_st = list(map(int,n_st))

    for i in range(len(n_st)):
        if not(n_st[i] in d):
            break
        if i == len(n_st)-1:
            flug = True

    if(flug):
        break
    n+=1

print(n)

Solution (Python):

price, count = list(map(int, input().split()))
hate_numbers = list(map(int, input().split()))

def is_ok(hates, price):
  for h in hates:
    if str(h) in list(str(price)):
      return False
  return True

for p in range(1, 100000):
  if is_ok(hate_numbers, p) is False:
    continue
  if p >= price:
    print(p)
    exit(0)

Solution (Python):
def main():
    n, k = map(int, input().split())
    d = set(list(map(str, input().split())))
    checker = 1
    while checker:
        if set(list(str(n))).isdisjoint(d):
            print(n)
            checker = 0
        else:
            n += 1

if __name__ == '__main__':
    main()

Solution (Python):
N,K=map(int,input().split())
li=list(map(int,input().split()))

N_keta=list(map(int,str(N)))

for n in range(100000):
  count=0
  for k in range(len(N_keta)):
    if N_keta[k] in li:
      count=1
      break
    
  if count==0:
    print(N)
    break
  else:
    N+=1
    N_keta=list(map(int,str(N)))

Solution (Python):
n, k = map(int, input().split())
d = set(map(str, input().split()))
num = {str(i) for i in range(10)}
available = num - d
ans = 0
for i in range(n, 10**5):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Solution (Python):
N, K = map(int, input().split())

l = set(input().split())

i = N
while(True):
  if(len(l & set(str(i))) == 0):
    print(i)
    break
  i += 1

Solution (Python):
n,k=map(int,input().split())
d = list((input().split()))

for i in range(n, 1000000):
  r = [x for x in list(str(i))]
  if list(set(r)&set(d))==[]:
    print(i)
    break

Solution (Python):

N,K = map(int,input().split())
D = tuple(map(str,input().split()))

for i in range(N,1000000):
    S = str(i)
    is_iroha = True
    for s in S:
        if s in D:
            is_iroha = False
            break
    if is_iroha:
        print(S)
        exit()

Solution (Python):
N,K = map(int,input().split())
D = set(list(map(int,input().split())))


for i in range(N,100001): 
    tmp = i 
    while tmp > 0 and tmp % 10 not in D:
        tmp = tmp // 10 
    if tmp == 0:
        print(i)
        break

Solution (Python):
N,K=map(int,input().split())
D=list(map(str,input().split()))

for i in range(N,10*N+1):
    if len(set(D)& set(list(str(i))))==0:
        print(i)
        break

Solution (Python):









def dec(i, D):
    for k in range(i - 1, -1, -1):
        if k not in D:
            return k
    return i

def inc(i, D):
    for k in range(i + 1, 10):
        if k not in D:
            return k
    return i

def max_dec_or_inc(A, start, D):
    for j in range(start, len(A)):
        d = dec(A[j], D)
        if d != A[j]:
            while d != A[j]:
                A[j] = d
                d = dec(A[j], D)
        elif A[j] in D: 
            u = inc(i, D)
            A[j] = u

def inc_one(A, end, D):
    for j in range(end - 1, -1, -1):
        up = inc(A[j], D)
        if up != A[j]:
            A[j] = up
            return j
    A.insert(0, inc(0, D))
    return 0

def f(n, D):
    out = list(map(int, str(n)))
    for j, i in enumerate(out):
        if i in D: 
            up = inc(i, D)
            if up != i: 
                out[j] = up
                
                max_dec_or_inc(out, j + 1, D)
            else: 
                out[j] = dec(i, D)
                
                idx = inc_one(out, j, D)
                
                max_dec_or_inc(out, idx + 1, D)
            break
    r = int("".join([str(x) for x in out]))
    return r

assert f(1000, [1, 3, 4, 5, 6, 7, 8, 9]) == 2000
assert f(9999, [0]) == 9999
assert f(6888, [8, 9]) == 7000
assert f(9999, [9]) == 10000
assert f(9999, [0, 9]) == 11111
assert f(9999, [0, 1, 9]) == 22222

n, k = map(int, input().split())
D = list(sorted(map(int, input().split())))
ans = f(n, D)
print(ans)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())

n = set(str(N))
ans = N
while True:
    for t in n:
        if t in D:
            break
    else:
        print(ans)
        exit()
    ans += 1
    n = set(str(ans))

Solution (Python):



import pdb
import sys
F = sys.stdin
N, K = F.readline().rstrip().split()
N = int(N)
K = int(K)
D = list(map(str,F.readline().rstrip().split()))

answer = None



while answer is None:
    Nstr = str(N)
    for i in range(len(Nstr)):
        if Nstr[i] in D:
            N += 1
            break

        if i == len(Nstr) - 1:
            answer = N

print(answer)