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())
D = list(map(int,input().split()))

f = [0]*10
for d in D:
    f[d] = 1

while True:
    check = str(n)
    for c in check:
        if f[int(c)]:
            n += 1
            break
    else:
        print(check)
        break

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

for i in range(n, 100000):
  m = str(i)
  count = 0
  for j in range(len(m)):
    if int(m[j]) in D:
      break
    else:
      count += 1
    if count == len(m):
      print(i)
      exit()
      
print(0)

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
ng = [False] * 10
for i in d:
    ng[i] = True
def ok(n):
    global ng
    while n > 0:
        if ng[n%10]:
            return False
        n //= 10
    return True
while not ok(n):
    n += 1
print(n)

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

Solution (Python):
n,t = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]

def check(x) -> bool:
    while x>0:
        a = x%10
        if a in d:
            return False
        x//=10
    return True

while check(n)==False:
    n+=1
print(n)

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

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))

Solution (Python):
def is_dislike(N, ds):
  num = N
  while(True):
    if (num % 10) in ds:
      return True
    else:
      num = int(num / 10)
      if num == 0:
        break
  return False


nk = list(map(int,input().split()))
N = nk[0]
K = nk[1]
ds = list(map(int,input().split()))
while(True):
  if is_dislike(N, ds):
    N = N+1
  else:
    print(N)
    break

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

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

while True:
  if len(set(str(n))&d) != 0:
    n+=1
    
  else:
    print(n)
    break

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

def solve(n):
  digits = str(n)
  for digit in digits:
    if int(digit) in d:
      return False
  return True

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

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

while True:
  if len(set(str(N)) & bl) != 0:
    N += 1
  else:
    print(N)
    break

Solution (Python):
n, k = list(map(int, input().split()))
d = list(input().split())
ans = n
find = False
while find == False:
    p = str(ans)
    find = True
    for i in range(len(p)):
        if p[i] in d:
            find = False
            break
    if find == False:
        ans += 1

print(ans)

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

while True:
    n = str(N)
    for i in range(K):
        f = 0
        if D[i] in n:
            N += 1
            f = 1
            break
    if f == 0:
        break

print(N)

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

def judge(num):
    for i in str(num):
        if i in unlike_list:
            return False
    return True

ans = False
while not ans:
    if judge(N):
        ans = True
    else:
        N += 1

print(N)

Solution (Python):
def main():
    N, K = map(int, input().split())
    A_list = list(map(str, input().split()))
    use_list = ["0","1","2","3","4","5","6","7","8","9"]
    list_A = list(set(use_list) - set(A_list))
    
    for i in range(100000) :
        ans = N + i
        
        ans_str = str(ans)
        frag = 0
        for val in ans_str :
            
            if str(val) in list_A :
                pass
                
            else :
                frag = 1
                break

        if frag == 0 :
            break
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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

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

E = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D

result = False
while result == False:
    for i in str(N):
        if not i in E:
            N = N + 1
            result = False
            break
        else:
            result = True
print(N)

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

def f(x):
    x=str(x)
    x=list(x)
    for i in x:
        if int(i) in d:
            return False
    return True

ans=n

while f(n)==False:
    n+=1
print(n)

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

def f(x):
    x=str(x)
    x=list(x)
    for i in x:
        if int(i) in d:
            return False
    return True

ans=n

while not f(n):
    n+=1
print(n)

Solution (Python):
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin=str(k)+str(find(0))*(len(n)-i-1)
        else:
            fin=str(find(1))+str(find(0))*len(n)
        break

print(fin)

Solution (Python):

from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







def IR(n): return [I() for i in range(n)]







def LIR(n): return [LI() for i in range(n)]







def SR(n): return [S() for i in range(n)]







def LSR(n): return [LS() for i in range(n)]







def SRL(n): return [list(S()) for i in range(n)]


n, k = LI()
d = LI()

limit = 11*n
while n < limit:
    flg = 1
    for x in list(str(n)):
        if int(x) in d:
            flg = 0
            break
    if flg:
        print(n)
        break
    n += 1

Solution (Python):

from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







def IR(n): return [I() for i in range(n)]







def LIR(n): return [LI() for i in range(n)]







def SR(n): return [S() for i in range(n)]







def LSR(n): return [LS() for i in range(n)]







def SRL(n): return [list(S()) for i in range(n)]


n, k = LI()

d = set(LI())
notd = list(set(range(10)) - d)
q = deque()
q.appendleft(0)
cnt = 0
ans = []
num = []

















limit = 11*n
while n < limit:
    flg = 1
    for x in list(str(n)):
        if int(x) in d:
            flg = 0
            break
    if flg:
        print(n)
        break
    n += 1

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

for i in range(n, 100001):
    flg = True
    s = str(i)
    for j in range(len(s)):
        if s[j] in a:
            flg = False
            break
    if flg:
        break
print(i)

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

i = n
while True:
    money = list(map(int, str(i)))
    for m in money:
        if dl.count(m) != 0:
            break
    else:
        print(i)
        break
    i += 1

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())


n,k = readInts()
D = Counter(readInts())
def ok(n):
    while n:
        v = n%10
        if D[v]:
            return False
        n //= 10
    return True
ans = n
for i in range(n, 100000):
    if ok(i):
        ans = i
        break
print(ans)

Solution (Python):
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('unko')

    @cc.export('main', '(i4, i4, i4[:])')
    def main(n, k, a):
        for i in np.arange(n, 100000):
            ok = 1
            j = i
            while j:
                m = j % 10
                for l in a:
                    if m == l:
                        ok = 0
                j //= 10
            if ok:
                print(i)
                break
    cc.compile()
    exit()


if __name__ == '__main__':
    from unko import main
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)

Solution (Python):
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline


@njit((i4, i4, i4[:]), cache=True)
def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = 1
        j = i
        while j:
            m = j % 10
            for l in a:
                if m == l:
                    ok = 0
            j //= 10
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)

Solution (Python):
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = True
        for j in str(i):
            ok &= j not in a
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = set(read().split())
    main(n, k, a)

Solution (Python):
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = True
        j = i
        while j:
            ok &= j % 10 not in a
            j //= 10
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)

Solution (Python):
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]







mod = 10**9 + 7

n,k = MI()
d = RI()

for i in range(n,100000):
    a = str(i)
    flag = True
    for j in a:
        if int(j) in d:
            flag = False
            break
    if flag:
        print(i)
        exit()

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
E = []
for i in range(10):
    if i not in D:
        E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
    if int(N[i]) not in E:
        ind = i
        break
if ind==len(N):
    print(N)
else:
    flag = 0
    x = ""
    for i in range(ind,-1,-1):
        n = int(N[i])
        for e in E:
            if e>n:
                x = N[:i]+str(e)+str(E[0])*(len(N)-i-1)
                flag = 1
                break
        if flag==1:break
    if flag==0:
        if E[0]>0:
            a = E[0]
        else:
            a = E[1]
        x = str(a)+str(E[0])*len(N)
    print(x)

Solution (Python):
N, K = map(int, input().split())
l = list(map(str, input().split()))
 
for i in range (N, 100000): 
	k = str(i)
	counter = 0
	for j in range (0, K):
		if k.find(l[j]) >= 0:
			counter+=1
	if counter == 0:
		print(i)
		exit()

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

while (True):
  if len(set(str(M)) & D) == 0:
    break
  M += 1
print(M)

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

for k in range(N,10**9):
    f = 1
    for e in str(k):
        if e in D:
            f = 0
            break
    if f == 1:
        print(k)
        exit(0)

Solution (Python):
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in range(n, 100000):
        s = np.array(list(map(int, str(i))), dtype=np.int64)
        ok = True
        for j in s:
            ok &= j not in a
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int64, sep=' ')
    a = np.fromstring(read(), dtype=np.int64, sep=' ')
    main(n, k, a)

Solution (Python):
import itertools
n,k = map(int, input().split())
d = list(map(int, input().split()))
safe = [i for i in range(10) if i not in d]

n_l = list(map(int, list(str(n))))
if len(set(safe)&set(n_l)) == len(set(n_l)):
    print(n)
    exit()

for v in itertools.product(safe, repeat=len(str(n))):
    if v[0] == 0: continue
    x = int("".join(list(map(str, v))))
    if int(x) >= n:
        print(x)
        exit()

for v in itertools.product(safe, repeat=len(str(n))+1):
    if v[0] == 0: continue
    x = int("".join(list(map(str, v))))
    if int(x) >= n:
        print(x)
        exit()

Solution (Python):
N, K, *D = map(int, open(0).read().split())
D = set(str(d) for d in D)
for i in range(N, 100_000):
    if set(str(i)) & D:
        continue
    print(i)
    break

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

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')


def main():

    N, K = MAPINT()
    D = LMAPSTR()
    
    str_n = str(N)
    
    for i in range(N, 100000):
      str_i = str(i)
      for s in str_i:
        if s in D:
          break
      else:
        print(str_i)
        exit()

        
if __name__ == "__main__":
    main()

Solution (Python):






import itertools

def main():
	N, K = [int(n) for n in input().split(" ")]
	D = [1] * 10
	for d in input().split(" "):
		D[int(d)] = 0
	L = [str(i) for i, v in enumerate(D) if v == 1]

	digit = len(str(N))
	cand = []
	for n in list(itertools.product(L, repeat=digit)):
		p = int("".join(list(n)))
		if p >= N:
			cand.append(p)
	if len(cand):
		print(min(cand))
	else:
		if L[0] == "0":
			print(str(L[1]) + "0" * digit)
		else:
			print(str(L[0]) * (digit + 1))


main()

Solution (Python):

import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)

if __name__ == '__main__':
    
    nk = list(map(int, input().split()))     

    x = nk[1]
    dList = list(map(int, input().split()))     

    
    f = 0
    n = nk[0]
    while f == 0:
        nList = [int(c) for c in str(n)]  
        b = 1
        for i in nList:
            for j in dList:
                if i == j:
                    b = 0
                    break
        if b == 1:
            break
        else:
            n += 1

    
    print("{}".format(n))

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



N,K=mint()
D=lint()
S=set([str(d) for d in D])

for x in range(N,100000):
    s=str(x)
    tmp=True
    for i in range(len(s)):
        if s[i] in S:
            tmp=False
            break
    if tmp:
        print(x)
        exit()

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


def f(n, x):
    if n==0:
        if x >= N:
            print(x)
            exit()
        return
    
    for i in range(10):
        if i in D:
            continue
        f(n-1, x*10+i)

f(len(str(N)), 0)
ans = ""
for i in range(1, 10):
    if i not in D:
        ans = str(i)
        break
for i in range(10):
    if i not in D:
        ans += str(i)*len(str(N))
        break
print(ans)

Solution (Python):
def iparse():
    return list(map(int, input().split()))

n, k = iparse()
d = iparse()

for i in range(n, 5000000):
    tmp = i
    f = True
    while tmp > 0:
        x = tmp % 10
        if x in d:
            f = False
            break
        tmp //= 10
    if f:
        print(i)
        exit()

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


def val(n):
    for i in str(n):
        if i in d:
            return
    print(n)
    exit()


while True:
    val(str(n))
    n += 1

Solution (Python):
n,k = map(int,input().split())
if k == 0:
  print(n)
  exit()
dislike = list(input().split())
 
ans = n-1
flag = 1
while flag == 1:
  ans+=1
  flag = 0
  for i in str(ans):
    if i in dislike:
      flag = 1
      break
print(ans)

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


temp=0
d ={}
a=1
b = {}
m = len(str(n)) +1 
over=False
while(a<=m and not over ):
  c = []
  d = 10**(a-1) 
  for v in ns:
    if a>1:
      for bv in b[a-1]:
        t = v*d + bv
        c += [t]
        if t >= n:
          print(t)
          over=True
          break
      if over:
        break
    else:
      t = v*d
      c += [t]
      if t >= n:
          print(t)
          over=True
          break
      
  b[a] = c
  a+=1

Solution (Python):
from itertools import product
N, K = map(int, input().split())
D = list(map(int, input().split()))
canuse = {0,1,2,3,4,5,6,7,8,9} - set(D)
canuse = list(canuse)
ans = float("inf")
for d in range(1, 6):
    for num in product(canuse, repeat=d):
        number = ""
        for m in num:
            number += str(m)
        number = int(number)
        if number >= N:
            ans = min(number, ans)
        
print(ans)

Solution (Python):
import itertools

def cal(N, target_num, keta):
    answer = float('inf')
    for p in itertools.product(target_num, repeat=keta):
        temp = 0
        for i, num in enumerate(p):
            temp += num * 10**i
            
        if temp >= N:
            answer = min(answer, temp)

    return answer

if __name__ == "__main__":
    N, K = map(int, input().split()) 
    D = set(list(map(int, input().split()))) 
    base = set(range(10))

    target_num = base - D
    keta = len(str(N))

    answer = min(cal(N, target_num, keta), cal(N, target_num, keta+1))

    print(answer)

Solution (Python):
import itertools

N, K = map(int, input().split()) 
D = set(list(map(int, input().split()))) 
base = set(range(10))

target_num = base - D
keta = len(str(N))

answer = float('inf')
for p in itertools.product(target_num, repeat=keta):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
        
    if temp >= N:
        answer = min(answer, temp)

for p in itertools.product(target_num, repeat=keta+1):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
        
    if temp >= N:
        answer = min(answer, temp)

print(answer)

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

while (s >= set(str(n))) == False:
  n += 1
  if (s >= set(str(n))) == True:
    ans = n
    break
    
print(ans)

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

while True:
  S=str(N)
  flag=True
  for x in S:
    if int(x) in D:
      flag=False
  if flag==True:
    break;
  N+=1
print(N)

Solution (Python):
def main():
    N, K = map(int, input().split())
    D = list(input().split())
    
    for i in range(N,100000):
        a = str(i)
        flag = True
        for d in D:
            if d in a:
                flag = False
                break
        if flag:
            print(i)
            exit()



if __name__ == "__main__":
    main()

Solution (Python):
def is_bad_nums(j: int, d: []) -> bool:
    while j:
        if j % 10 in d:
            return True
        j //= 10
    return False


def answer(n: int, k: int, d: []) -> int:
    for i in range(n, 100000):
        if is_bad_nums(i, d):
            continue
        return i


def main():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    print(answer(n, k, d))


if __name__ == '__main__':
    main()

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
num = str(list(set(num) ^ set(D)))

ans = str(N)
clear = 0

while clear == 0:
    for i in range(len(ans)):
        if not ans[i] in num:
            break
        if i == len(ans) - 1:
            clear += 1  
    ans = str(int(ans) + 1)

print(int(ans) - 1)

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

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

def ok(x):
    while x:
        if x % 10 in D:
            return False
        x //= 10
    return True

for i in range(N,100000):
    if ok(i):
        print(i)
        exit()

Solution (Python):
def price(N,K):
    Kn = input().split()
    Flag = False

    for i in range(N,10*N,1):
        value = str(i)
        for j in range(K):
            if(Kn[j] not in value):
                Flag = True
            elif(Kn[j] in value):
                Flag = False
                break

        if(Flag == True):
            print(i)
            break

N,K = (int(x) for x in input().split())
price(N,K)

Solution (Python):
import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():

    n, k = input_int_list()
    D = input_int_list()

    
    
    

    for i in range(n, 100000):
        flag = True
        for j in str(i):
            if int(j) in D:
                flag = False
            if not flag:
                break
        if flag:
            print(i)
            return

    return


if __name__ == "__main__":
    main()

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,k = I()
d = l()
use = [i for i in range(11) if i not in d ]
a = True
price = n

while a:
    cnt = 0
    for i in str(price):
        a = len(str(price))
        if int(i) not in d:
            cnt += 1
        else:
            cnt = inf
        if a == cnt:
            print(price)
            sys.exit()
    price += 1

Solution (Python):
n, k = map(int, input().split())
D = set(input())
for i in range(n, 10**5):
  if set(str(i)) & D == set():
    print(i)
    exit()

Solution (Python):
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))
d0 = D[0]

def dfs(M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(M+[d0], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(M+[d], i+1, 0)
        elif d > N[i]:
            dfs(M+[d], i+1, 1)
            break
    if d0:
        dfs([d0], 0, 1)
    else:
        dfs([D[1]], 0, 1)
dfs([], 0, 0)

Solution (Python):
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))

def dfs(N, M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(N, M + [D[0]], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(N, M+[d], i+1, 0)
        elif d > N[i]:
            dfs(N, M+[d], i+1, 1)
            break
    if D[0] == 0:
        dfs(N, [D[1], D[0]], 1, 1)
    else:
        dfs(N, [D[0], D[0]], 1, 1)

dfs(N, [], 0, 0)

Solution (Python):
n, k = map(int, input().split())
ds = [d for d in input().split()]
while any(c in ds for c in str(n)): n += 1
print(n)

Solution (Python):
import itertools

n,k=map(int,input().split())
d=list(input())
x=[]
ans=float('inf')

for i in range(10):
  if str(i) not in d:
    x.append(str(i))
    
for i in range(1,6):
  for lst in itertools.product(x,repeat=i):
    if int(''.join(lst))>=n:
      ans=min(ans,int(''.join(lst)))
      

print(ans)