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=set(input().split())
while True:
    for c in str(n):
        if c in d:
            n+=1
            break
    else:
        print(n)
        exit()

Solution (Python):
import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy

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

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

    pay = N
    while True:
        if any(c in D for c in map(int, str(pay))):
            pay += 1
            continue
        print(pay)
        return


if __name__ == '__main__':
    main()

Solution (Python):
import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy

N,K=map(int,input().split())
D=list(map(int,input().split()))
for i in range(N,100000):
    t=set(map(int,list(str(i))))
    temp=D+list(t)
    temp2=set(temp)
    if len(temp)==len(temp2):
        
        
        print(i)
        exit()

Solution (Python):
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    digits = {x for x in range(10)}
    digits -= D
    
    digits = sorted(digits)

    def dfs(pay):
        if pay >= N:
            return pay

        np = pay * 10

        ret = 1 << 60
        if np == 0 and 0 in digits:
            for d in digits:
                if d == 0: continue
                ret = min(ret, dfs(np + d))
        else:
            for d in digits:
                ret = min(ret, dfs(np + d))
        return ret

    print(dfs(0))


if __name__ == '__main__':
    main()

Solution (Python):
n,l = map(int,input().split())
num = set(map(int,input().split()))
ans=0
for i in range(n,10*n):
  for j in range(len(str(i))):
    if int(str(i)[j]) in num:
      if j==0:
        i = (int(str(i)[0])+1)*(10**(len(str(i))-1))   
      break
    if j ==len(str(i))-1:
      ans=i
  if ans!=0:
    break
print(ans)

Solution (Python):
from itertools import product
n, k = list(map(int, input().split()))
dl = list(map(int, input().split()))
target = []
for i in range(10):
    if i not in dl:
        target.append(i)

ansl = []
for R in range(1, 6):
    for bit in product(target, repeat=R):
        t = 0
        for i, b in enumerate(bit):
            t += (10**i)*b
        
        if t >= n:
            ansl.append(t)
print(min(ansl))

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

digitlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for d in D:
    digitlist.remove(d)

Keta = len(str(N))
Ans = ''


def clear(X):
    if len(X) == Keta:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear(X)
            X = X[:-1]


def clear2(X):
    if len(X) == Keta+1:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear2(X)
            X = X[:-1]



clear(Ans)
clear2(Ans)

Solution (Python):

from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

init = [str(i) for i in range(10) if i not in D and i != 0]
use = [str(i) for i in range(10) if i not in D]
q = deque(init)
ans = []
while q:
    num = q.pop()
    if int(num) >= N:
        ans.append(num)
        continue
    for u in use:
        q.append(num + u)

print(min(list(map(int, ans))))

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
num = n
while True:
    is_match = True
    for c in str(num):
        if int(c) in d:
            is_match = False
            break
    if is_match:
        break
    num += 1
print(num)

Solution (Python):
n,k = map(int,input().split())
d = list(map(str, input().split()))
 
while True:
    if sum([i in d for i in list(str(n))]) == 0:
        print(n)
        break
    n+= 1

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
flag=0
m=n
while (flag==0):
    str_m=list(str(m))
    for j in d:
        if(j in str_m):
            m+=1
            flag=2
            break
    if(flag==2):
        flag=0
        continue
    else:
        flag=1

print(int(m))

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

while(1):
    n_str = list(str(n))
    if sum([i in ds for i in n_str]) == 0:
        print(n)
        break
    n += 1

Solution (Python):
K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
flag = False
while True:
  K_str = str(K)
  for i in range(len(K_str)):
    for j in range(len(D)):
      if K_str[len(K_str)-1-i]==str(D[j]):
        flag=False
        break
      if j==len(D)-1:
        flag = True

    if not flag:
      break

  if flag:
    break
  K+=1

print(K)

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

n,k=map(int,input().split())
d=list(map(int,input().split()))
res=[]
for i in range(10):
  if i not in d:
    res.append(i)
ans=0
ansmax=0
ansmin=0
n_s=str(n)
l=len(n_s)
M=max(res)
for i in range(l):
    ansmax+=M*10**(l-i-1)
if n>ansmax:
    if res[0]!=0:
        ans=res[0]*10**l
    else:
        ans=res[1]*10**l
    for i in range(l):
        ans+=res[0]*10**(l-i-1)
    print(ans)
    exit()
res=np.array(res)
flag=False
for i in range(l):
    j=n//(10**(l-i-1))
    if not flag:
        if j not in res:
            p=np.searchsorted(res,j, side="left")
            m=res[p]
            ans+=m*10**(l-i-1)
            flag=True
            continue
        else:
            ans+=j*10**(l-i-1)
    if flag:
        ans+=res[0]*(10**(l-i-1))
    n=n%(10**(l-i-1))
print(ans)

Solution (Python):
N,K= map(int,input().split())
D = [int(j) for j in input().split()]
D2 = list(set([i for i in range(0,10)])-set(D))
def f(N,D):
    if len(set([int(i) for i in list((str(N)))])&set(D))==0:
        return True
    else:
        return False
if len(D2) ==0:
    print(N)
else:
    while not f(N,D):
        N+=1
print(N)

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
l = [i for i in range(10)]
for i in range(K):
  l.remove(D[i])

ansl = []
def dfs(s):
  if len(s) < len(str(N))+1:
    for i in l:
      new = s+str(i)
      ansl.append(int(new))
      dfs(new)
dfs("")
ansl.sort()
for i in ansl:
  if i >= N:
    print(i)
    break

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


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


def main():
    N, _ = readnums()
    d = set(readstrs())
    for i in range(N, 100000):
        for digit in tuple(str(i)):
            if digit in d:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    main()

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

use = [i for i in range(10)]

for _d in d:
    use.remove(_d)


while True:
    ok = True
    s = str(n)
    for i in range(len(s)):
        if int(s[i]) not in use:
            ok = False
            break

    if ok:
        print(n)
        exit()
    else:
        n += 1

Solution (Python):
N, K = 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))

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)

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,1000000):
  s=str(i)
  ok=True
  t_str=""
  for ss in s:
    if int(ss) in d:
      ok=False
      break
    t_str+=ss
  if ok:
    print(int(t_str))
    exit(0)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    D = set(list(map(int, input().split())))

    def dfs(L):
        if len(L) == 6:
            return

        for i in range(10):
            if i not in D:
                L.append(str(i))
                res = int("".join(L))
                if res >= n:
                    ans.append(res)
                dfs(L)
                L.pop()

        return ans

    ans = []
    dfs([])
    ans.sort()
    for i in ans:
        if n <= i:
            print(i)
            break


if __name__ == '__main__':
    resolve()

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

for i in range(N,10**9):
    S=str(i)
    ok=True
    for s in S:
        if int(s) in D:
            ok=False
    if ok:
        ans=i
        break

print(ans)

Solution (Python):
def solve():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    while True:
        S = list(str(N))
        for s in S:
            if int(s) in D:
                break
        else:
            return N
        N += 1
print(solve())

Solution (Python):

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


def ok(s):
    for c in s:
        if c in D:
            return False
    return True


i = N
while True:
    s = str(i)
    if ok(s):
        print(s)
        exit()
    i += 1

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

ans = float("INF")
for v in itertools.product(d, repeat=len(str(n))):
  if v[0] != "0" and int("".join(v)) >= n:
    if ans > int("".join(v)): ans = int("".join(v))
if ans == float("INF"):
  for v in itertools.product(d, repeat=len(str(n))+1):
    if v[0] != "0" and int("".join(v)) >= n:
      if ans > int("".join(v)): ans = int("".join(v))
print(ans)

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

if __name__ == '__main__':
    main()

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

n,k=map(int,input().split())
d=[int(i) for i in input().split()]
for i in range(1,100001):
    if i<n:
        continue
    now=str(i)
    for j in now:
        if int(j) in d:
            break
    else:
        print(now)
        sys.exit()

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

for i in range(N, 100 * N):
    if set(list(str(i))) <= D:
        print(i)
        exit()

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

ans = n
while True:
    for i in list(map(int, str(ans))):
        if i in D:
            break
    else:
        print (ans)
        exit ()

    ans += 1

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


ok_lst = [x for x in range(0, 10) if x not in D]
ok_lst.sort(reverse = True)
stack = deque([x for x in ok_lst if x != 0])
ans_list = []

while len(stack) > 0:
    
    
    now_num = stack.pop()
    
    
    if now_num >= n:
        ans_list.append(now_num)
        continue
    
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        next_num = int(next_num)
        stack.append(next_num)

print(min(ans_list))

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

ans = n
flag = True
while flag:
  flag = False
  for x in d:
    if x in str(ans):
      ans += 1
      flag = True
      continue
      
print(ans)

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
for j in range(n, 100000):
    flg=False
    for s in set(str(j)):
        if s in d:
            flg=True
            break
    if flg==False:
        print(j)
        break

Solution (Python):
ma = lambda :map(int,input().split())
n,k = ma()
D = set(input().split())
for i in range(n,10*n+1):
    if set(list(str(i))) & D:
        pass
    else:
        print(i)
        exit()

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

yet=True
while yet:
    yet=False
    for i in list(str(n)):
        if i in d:
            yet=True
            break
    n+=1

print(n-1)

Solution (Python):


import sys






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    dislike = input().split()

    start = n
    while True:
        
        for digit in str(start):
            if digit in dislike:
                start += 1
                break
        else:
            print(start)
            exit()


if __name__ == "__main__":
    main()

Solution (Python):


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

nums = list(set([i for i in range(10)]) - set([int(i) for i in input().split()]))


def dfs(nums, t, n, path):
    if int(t) >= n:
        path.append(int(t))
        return
    if len(t) > 7:
        return
    for num in nums:
        dfs(nums, t + str(num), n, path)
path = []
dfs(nums, '0', n, path)
path.sort()
ans = path[0]
print(ans)

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

Solution (Python):
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()

Solution (Python):
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()

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

price = N

flag = "like"
ans_flag = 0

while ans_flag == 0:
  for i in range(len(str(price))):
    if int(str(price)[i]) in d:
      flag = "dislike"
  if flag == "dislike":
    price +=1
    flag ="like"
  else:
    ans_flag = 1
print(price)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

"""
lim = 2*10**5   


fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod


fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod

"""

N, K = MAP()
D = LIST()

while 1:
	if set(list(str(N))) & set(D) == set():
		print(N)
		break
	N += 1

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

while True:
    for i in str(N):
        if int(i) in D:
            N += 1
            break
    else:
        break
print(N)

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
UN = [i for i in range(10)]
for i in D:
    UN.remove(i)

n = str(N)
N_keta = len(n)

for i in n:
    if int(i) not in UN:
        break
else:
    print(N)
    exit()

ex_0 =  [i for i in UN if i > 0]

if N_keta == 1:
    if N < max(UN):
        _11 =[i for i in UN if i > N]
        print(min(_11))
    else:
        print(min(ex_0) * 10 + min(UN))

if N_keta == 2:
    if N < max(UN) * 11:
        for i in UN:
            for j in UN:
                _2 = i * 10 + j
                if  _2 > N:
                    print(_2)
                    exit()
    else:
        print(min(ex_0) * 100 + min(UN) * 11)

if N_keta == 3:
    if N < max(UN) * 111:
        for i in UN:
            for j in UN:
                 for k in UN:
                     _3 = i * 100 + j * 10 + k
                     if _3 > N:
                         print(_3)
                         exit()
    else:
        print(min(ex_0) * 1000 + min(UN) * 111)

if N_keta == 4:
    if N < max(UN) * 1111:
        _4 = [i for i in UN if i >= int(n[0])]
        for i in _4:
            for j in UN:
                for k in UN:
                    for l in UN:
                        _41 = i * 1000 + j * 100 + k * 10 + l
                        if _41 > N:
                            print(_41)
                            exit()
    else:
        print(min(ex_0) * 10000 + min(UN) * 1111)

Solution (Python):
def main():
    from itertools import combinations_with_replacement,permutations
    n, k = map(int, input().split())
    *d, = input().split()
    m = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} - set(d)
    m = list(m)
    m.sort()
    mm = ""
    if m[0] != "0":
        mm = m[0]
    else:
        mm = m[1]

    l = len(str(n))
    t = set()
    for s in combinations_with_replacement(m, l):
        for xx in permutations(s):
            w = "".join(xx)
            ww = mm + w
            t.add(int(w))
            t.add(int(ww))

    t = list(t)
    t.sort()
    for x in t:
        if x >= n:
            print(x)
            break


if __name__ == '__main__':
    main()

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

while True:
    l = str(n)
    for i in l:
        if i in s:
            break
    else:
        break
    n += 1
print(n)

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

for i in range(N, 100001):
    if set(list(str(i))) & set(D):
        gg = 1
    else:
        print(i)
        break

Solution (Python):
import numpy as np
N, _ = map(int, input().split())
D = np.bincount(tuple(map(int, input().split())), minlength=10)
while True:
    n = N
    while n:
        if D[n % 10]:
            break
        n //= 10
    else:
        break
    N += 1
print(N)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N, K = getNM()
intlist = [i for i in range(10)]
D = getList()
for i in D:
    if i in D:
        
        intlist.pop(intlist.index(i))

anslist = []



def dfs(i, num):
    anslist.append(num)
    
    if i < 5 and num < N:
        for j in intlist:
            newnum = int(str(num) + str(j))
            dfs(i + 1, newnum)

for i in intlist:
    if i != 0:
        dfs(1, i)

anslist.sort()

for i in anslist:
    if i >= N:
        ans = i
        break
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N, K = getNM()
intlist = [i for i in range(10)]
D = getList()
for i in D:
    if i in D:
        intlist.pop(intlist.index(i))

anslist = []
def dfs(i, num):
    anslist.append(num)
    if i < 5:
        for j in intlist:
            newnum = int(str(num) + str(j))
            dfs(i + 1, newnum)

for i in intlist:
    if i != 0:
        dfs(1, i)

anslist.sort()

for i in anslist:
    if i >= N:
        ans = i
        break
print(ans)

Solution (Python):
N,K=map(int,input().split())
Dlist=list(map(int,input().split()))
flag=True
i=0
while flag:
    ans=str(i)
    num=0
    if i>=N:
        
        for j in range(len(ans)):
            if int(ans[j]) not in Dlist:
                num+=1
            if num==len(ans):
                print(i)
                flag=False
    i+=1

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
flag = False
while True:
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        if c in use:
            flag = True
        else:
            flag = False
            break
    if flag:
        print(n)
        sys.exit()
    n += 1

Solution (Python):
n,k = map(int,input().split())
L = list(map(int,input().split()))
num = [1,2,3,4,5,6,7,8,9,0]
li = list(set(num).difference(set(L)))

flag = False
while True:
    n = str(n)
    for i in range(len(n)):
        if int(n[i]) in li:
            flag = True
        else:
            flag= False
            break
    if flag:
        print(n)
        exit()
    n = int(n)
    n +=1

Solution (Python):
n, k = [int(i) for i in input().split()]
dd = [int(i) for i in input().split()]

ans = n
flg = True
while flg:
    for s in str(ans):
        if int(s) in dd:
            ans += 1
            break
    else:
        flg = False
print(ans)

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

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

a,b = cin()
a = list(str(a))
x = []
for i in a:
    x.append(int(i))
c = cina()
d = {0,1,2,3,4,5,6,7,8,9}
e = d.difference(c)
s = ""
index = -1
test = 0
no = 0
for i in range(len(x)):
    check = False
    for j in c:
        if x[i]==j:
            check = True
    if check:
        for j in e:
            if j>x[i]:
                if test==0:
                    x[i] = j
                    index = i
                test += 1
                break
    else:
        no += 1

if no==len(x):
    for i in x:
        s += str(i)
elif test==0:
    q = e.difference({0})
    g = list(q)
    g.sort()
    s += str(g[0])
    ap = ""
    if 0 in e:
        ap = '0'*len(a)
    else:
        ap = str(g[0])*len(a)
    s += ap
else:
    w = list(e)
    for i in range(0,index+1):
        s += str(x[i])
    ap = str(w[0])*(len(x)-index-1)
    s += ap

print(s)

Solution (Python):
n,k = input().split()
hate_num = input().split()
num = int(n)
boo = False
while(boo == False):
  dec = []
  for i in str(num):
    dec.append(i not in hate_num)
    
  if(False not in dec):
    boo = True
  num += 1
    
print(num-1)

Solution (Python):
n, k = (int(x) for x in input().split())
ds = [int(x) for x in input().split()]
xs = list(filter(lambda x: x not in ds, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
o = n
m = len(str(n))
ans = 0
c = False
for i in range(m):
    d = (o // 10 ** i) % 10
    ys = list(filter(lambda x: x >= d, xs))
    if len(ys) == 0:
        if i == m - 1:
            y = xs[0] * 11 if xs[0] != 0 else xs[1] * 10
        else:
            y = xs[0]
        o += (y - d) * 10 ** i + 10 ** (i + 1)
        ans += y * 10 ** i
    else:
        y = ys[0]
        if y > d:
            ans = y * 10 ** i
            for j in range(i):
                ans += xs[0] * 10 ** j
        else:
            ans += y * 10 ** i
print(ans)

Solution (Python):
n, k = map(int, input().split())
d = set(list(map(str, input().split())))
for i in range(n, 10**6):
    w = True
    idx = 0
    i = str(i)
    while idx < len(str(i)):
        if i[idx] in d:
            w = False
            break
        idx += 1
    if w:
        print(i)
        exit()

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
n=[int(x) for x in str(n)]

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

import bisect
for i in range(len(n)-1,-1,-1):
    if n[i]>ok[len(ok)-1]:
        for j in range(i,len(n)):
            n[j]=str(ok[0])
        if i>0:
            n[i-1] += 1
        else:
            if ok[0]==0:
                n.insert(0,str(ok[1]))
            else:
                n.insert(0,str(ok[0]))
    else:
        num=bisect.bisect_left(ok,n[i])
        if n[i]<ok[num]:
            for j in range(i+1,len(n)):
                n[j]=str(ok[0])
        n[i]=str(ok[num])

n=int(''.join(n))
print(n)

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

not_D = []
siharai = []
for i in range(0,10):
  if i not in D:
    not_D.append(i)


c = list(itertools.product(not_D,repeat = len(str(N))))
c += (list(itertools.product(not_D,repeat = len(str(N))+1)))

for row in c:
  num = ""
  for i in row:
    num += str(i)
  siharai.append(int(num))

  
for i in siharai:
  if i >=N:
    print(i)
    break

Solution (Python):



N,K = map(int, input().split())
D = list(map(int, input().split()))
nums = set([0,1,2,3,4,5,6,7,8,9])
nums -= set(D)


ans = []
def func(s, nums):
    global ans
    if len(s) >= len(str(N)):
        if int(s) >= N:
            ans.append(int(s))

        
    if len(s) > len(str(N))+1:
        return

    for i in nums:
        func(s[:] + str(i), nums)


func("", nums)
ans.sort()
print(ans[0])

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

while True:
    if all(n not in D for n in str(N)):
        print(N)
        exit()
    else:
        N += 1

Solution (Python):
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int(s) for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in D:
    Da.remove(i)
Da_str = [str(j) for j in Da]
 
a_1 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]
 
for i in nu:
    if i >= int(N):
        print(i)
        break

Solution (Python):
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())
D = set(map(str, sys.stdin.readline().rstrip().split()))


for i in range(N, N*10+1):
    price_str = str(i)
    for num_str in price_str:
        if num_str in D:
            break
    else:
        print(price_str)
        sys.exit()

Solution (Python):
def main():
    from sys import stdin
    n,k = map(int,stdin.readline().rstrip().split())
    Ds = set(map(int,stdin.readline().rstrip().split()))

    ans = n
    while True:
        num = ans
        numset = set()
        while num != 0:
            r = num%10
            num = num//10
            numset.add(r)
        if numset & Ds == set({}):
            break;
        else:
            ans+=1
    
    print(ans)
main()

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

number = list(range(10))
number = [str(x) for x in number if x not in d]

ans = []
for v in itertools.product(number, repeat=len(n)):
  if v[0] == "0": continue
  if int("".join(v)) >= int(n): ans.append(int("".join(v)))

if not ans:
  for v in itertools.product(number, repeat=len(n)+1):
    if v[0] == "0": continue
    if int("".join(v)) >= int(n): ans.append(int("".join(v)))

print(min(ans))

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    D = list(map(str, input().split()))

    for i in range(N, 10 ** 5):
        s = str(i)
        hated = False
        for d in D:
            if d in s:
                hated = True
        if not hated:
            ans = i
            break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
while True:
    l = [s for s in str(N)]
    f = True
    for n in set([int(x) for x in l]):
        if n in lst:
            f = False
            break
    if f:
        print(N)
        exit()
    N += 1

Solution (Python):

def main():
    N, K = input().split(" ")

    D = list(input().split(" "))
    use_num = list(set([str(i) for i in range(10)]) - set(D))

    N = int(N)
    i = N
    while True:

        if not set(str(i)) <= set(use_num) and i >= N:
            i += 1
        else:
            print(i)
            break

if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, K = input().split(" ")

    D = list(input().split(" "))
    use_num = list(set([str(i) for i in range(10)]) - set(D))

    N = int(N)
    i = N
    while True:

        if not set(str(i)) <= set(use_num) and i >= N:
            i += 1
        else:
            print(i)
            break

if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))
ok_lst = [x for x in range(0, 10) if x not in D]
stack = deque([x for x in ok_lst if x != 0])
while len(stack) > 0:
    now_num = stack.popleft()
    if now_num >= n:
        print(now_num)
        break
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        stack.append(int(next_num))

Solution (Python):
n, k = map(int, input().split())
d = list(map(str, input().split()))
"""
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(k):
    for j in range(len(l)):
        if d[i] == l[j]:
            l.pop(j)
            break
"""
while True:
    tmp = list(str(n))
    flag = True
    for i in range(len(d)):
        if d[i] in tmp:
            flag = False
            break
    if flag:
        break
    n += 1
print(n)