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):
from itertools import product

N, K = map(int, input().split())
D = list(map(int, input().split()))
L = []
for i in range(10):
	if not i in D:
		L.append(i)
keta = len(str(N))
flg = 0


for num in product(L, repeat = keta):
	num = list(num)
	num.reverse()
	
	val = 0
	for i in range(keta):
		val += num[i] * (10 ** i)
	if val >= N:
		flg = 1
		break
		
if flg:
	print(val)

else:
	for l in L:
		if l != 0:
			a = l
			break
	val = a * (10 ** (keta))
	for i in range(keta):
		val += min(L) * (10 ** i)
	print(val)

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

for i in range(n,100000):
    sn=str(i)
    ok=True
    for num in sn:
        if int(num) in d:
            ok=False
    if ok:
        print(i)
        exit()

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

Solution (Python):
N,K=map(int,input().split())
D=list(map(str,input().split()))
for k in range(9*N):
    N += 1
    for j in range(len(str(N-1))):
        if str(N-1)[j] in D:
            break
    else:
        print(N-1)
        exit()

Solution (Python):

import sys


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

    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):
N, K = map(int, input().split())
D = set(input())
while True:
    if D & set(str(N)):
         N += 1
         continue
    else:
        print(N)
        break

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

while True:
    for c in str(n):
        if c in d:
           break
    else:
        print(n)
        exit()
    n +=1
print(n)

Solution (Python):
n, k = map(int, input().split())
list_num = [i for i in input().split()]
price = n
while True :
    i = 0
    for i in range(len(str(price))) :
        if str(price)[i] in list_num :
            price += 1
            break
    else :
        print(price)
        break

Solution (Python):
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)





def func(s, i, over):
    if i == len(s):
        return ""
    
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)
    return "10" + func(s, i+1, over=True)

def solve(N, D):
    D = set(list(D))
    while True:
        ok = True
        for c in str(N):
            if c in D:
               ok = False
               break
        if ok:
            return N
        N+=1

print(solve(N, D))

Solution (Python):




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

    while True:
        if all([True if n not in D else False for n in list(str(N))]):
            break
        N += 1
    print(N)


if __name__ == "__main__":
    main()

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

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

print(ans)

Solution (Python):
numbers = [str(e) for e in range(10)]
n, k = map(int, input().split())
hate_list = [e for e in input().split()]
available = set(numbers) - set(hate_list)
for i in range(n, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()
d_s = set(D)
moto = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
amari = d_s & moto
l = list(str(N))
l = map(int, l)


i = N
while 1:
    
    l = list(str(i))
    l = list(map(int, l))
    l_s = set(l)
    s_intersection = d_s & l_s
    
    if len(s_intersection) == 0:
        print(i)
        exit()
    i += 1

Solution (Python):
n, k = map(int, input().split())
d_k = set(map(int, input().split()))
ans = n
while ans <= n * 10:
    isOK = True
    for x in range(len(str(ans))):
        if int(str(ans)[x]) in d_k: 
            isOK = False
            break
    if isOK == True: break
    ans += 1
print(ans)

Solution (Python):
n, k = list(map(int, input().rstrip().split()))
d = list(map(int, input().rstrip().split()))
ans = n
while (True):
    x = ans
    flag = 1
    while x > 0:
        r = x % 10
        x = x // 10
        if r in d:
            ans += 1
            flag = 0
            break
    if flag == 1:
        break
print(ans)

Solution (Python):
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n))
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


if dfs(0, 0) != inf:
    print(dfs(0, 0))
else:
    stop += 1
    print(dfs(0, 0))

Solution (Python):
n, k, *d = map(int, open(0).read().split())
d = set(d)

while 1:
    for i in str(n):
        if int(i) in d: break
    else:
        print(n)
        break
    n += 1

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

amount = n
while 1:
  s_amount = str(amount)
  for d in s_amount:
    if d in ds:
      break
  else:
    break
  amount += 1
print(amount)

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

for i in range(n,10**6+1):
    s = str(i)
    for j in d:
        if j in s:
            break
    else:
        print(i)
        break

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

for i in range(n, 100000):
    if set(str(i)).intersection(dl) == set():
        print(i)
        break

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

for i in range(N, 99999) :
  chk = [int(i) for i in str(i)]
  if len(set(chk) & set(D)) == 0:
    print(i)
    break

Solution (Python):

N, K = map(int, input().split())
set_D = {str(int(x)) for x in input().split()}

ans = N

while True :
    if set(str(ans)).intersection(set_D) :
        ans += 1
    else :
        break

print(ans)

Solution (Python):
s = input().split(" ")
n = int(s[0])
numbers = [ i for i in input() if i != " "]
 
for i in range(n, 100001):
  found = False
  snum = str(i)
  for num in numbers:
    if num in snum:
      found = True
      break
  
  if found == False:
     print(i)
     break

Solution (Python):
from itertools import product
N, K = map(int, input().split())
D = set(map(int, input().split()))
C = set(i for i in range(10))
C -= D
B = sorted(str(c) for c in C)
for i in range(1, 10):
    for p in product(B, repeat=i):
        s = "".join(p)
        if int(s) >= N:
            print(s)
            exit()

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

while True:
    flag = True
    str_N = str(N)
    for i in range(len(str_N)):
        if str_N[i] in D:
            flag = False
    if flag:
        print(N)
        exit()
    N += 1

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

Solution (Python):
n,k = map(int,input().split())
d = [i for i in input().split()]
flag = True

while flag:
    for c in str(n):
        if c in d:
            n += 1
            break
    else:
        flag = False
    
print(n)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
for n in range(N, 100000):
  if set(str(n)).isdisjoint(D): break
print(n)

Solution (Python):
import itertools

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

default=[0,1,2,3,4,5,6,7,8,9]

for i in D:
    if i in default:
        default.remove(i)
price=[]
for cost in itertools.product(default, repeat=len(str(N))):
    price.append(int(''.join(list(map(str,list(cost))))))

price.sort()

price=[i for i in price if i>=N]

if len(price)>=1:
    print(price[0])
else:
    N_len=len(str(N))
    default2 = [i for i in default if i >= 1]
    default2.sort()
    default.sort()
    print(str(default2[0])+str(default[0])*(N_len))

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

for i in range(N,10**5):
    l = set(list(str(i)))
    if l & D:
        continue
    print(i)
    break

Solution (Python):
N,K=map(int,input().split())
D=list(input().split())
A=set(D)
for i in range(N,10*N+1):
  if len(set(str(i))&A)==0:
    print(i)
    break

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

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

while True:
  s_l = list(str(n))
  frag = True
  for de in d:
    if de in s_l:
      frag = False
      continue
  if frag:
    print(n)
    break
  n += 1

Solution (Python):
n, k = map(int, input().split())
A = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - set(input().split())
while True:
  s = set(str(n))
  if s <= A:
    print(n)
    break
  n += 1

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

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

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

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

Solution (Python):
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]

d = input().split()
a = True
for i in range(N, 90001):
  a = True
  for j in d:
    if str(i).count(j) > 0:
      a = False
      break
  if a:
    print(i)
    break

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

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

Solution (Python):
def is_valid(A, D):
    while A > 0:
        if (A%10) in D:
            return False
        else:
            A = A//10
    return True
    
N, K = map(int, input().split())
D = list(map(int, input().split()))

while is_valid(N, D) == False:
    N += 1

print(N)

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

Solution (Python):
N, _ = list(map(int, input().split()))
d = set(list(input().replace(" ", "")))

for i in range(N,10*N+1):
  n = str(i)
  ns = set(list(n))
  flg = False
  for t in ns:
    if t in d:
      flg = True
      break
  if flg == False:
    print(n)
    exit()
print(0)

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  S = str(ND[0])
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  j = 10 - K
  cnt = 0
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    if l == j:
      l, s = 0, 0
      j *= 10 - K
      cnt += 1
    for x in range(cnt+1):
      F += ND[s%(10 - K)] * ju
      ju *= 10
      s //= 10 - K
  print(F)

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

def main():
    N, K = [int(x) for x in input().split()]
    D = [int(x) for x in input().split()]

    Dset = set(D)

    for i in range(N, 1000000):
        for j in str(i):
            if int(j) in Dset:
                break
        else:
            print(i)
            return


    
    
    

if __name__ == '__main__':
    main()

Solution (Python):
n, k = input().split()
ds = input().split()
ns = {_n for _n in n} 
ds = { d for d in ds}

result = 1
while(True):
    rs = {r for r in str(result)}
    if result >= int(n) and len(rs&ds) == 0 :
        print(result)
        break
    else:
        result += 1

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

ans = n
flag = True

while flag:
  stans = str(ans)
  array = list(map(int, stans))
  sa = set(array)
  
  if sa & ds == set():
    flag = False
  else:
    ans += 1
    
print(ans)

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

ok = set(("0","1","2","3","4","5","6","7","8","9"))-set(D)

def solve(str_num):
    ans = 100000
    if str_num == "":
        for c in ok:
            if c == "0":
                continue
            ans = min(ans,solve(str_num+c))

    else:
        for c in ok:
            new_num = str_num+c
            if N <= int(new_num):
                ans = min(ans,int(new_num))
            else:
                ans = min(ans,solve(new_num))
    return ans

if N<10:
    ans = 100000
    for c in ok:
        if N <= int(c):
            ans = min(ans,int(c))
    if ans == 100000:
        print(solve(""))
    else:
        print(ans)
else:
    print(solve(""))

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

for i in range(n,n*10+1):
    if i>=n and len(set(map(int,str(i)))&D)==0:
        print(i)
        break

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, k = list(map(int, input().strip().split()))
    d = input().strip().split()
    ans = n
    while True:
        sans = str(ans)
        flag = False
        for c in sans:
            
            
            if c in d:
                ans += 1
                flag = True
                break
        if flag:
            continue
        print(sans)
        return

    

if __name__ == '__main__':
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    D = LS()
    for price in range(N, 100000):
        valid = True
        for dig in D:
            if dig in str(price):
                valid = False
                break
        if valid:
            break
    print(price)

main()

Solution (Python):
N,K = map(int, input().split())
lst = list(map(str, input().split()))
while True:
    flag = True
    for elem in list(str(N)):
        if elem in lst:
            flag = False
            break
    if flag:
        print(N)
        break
    N +=1

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
ok = [1] * 10
for i in d:
    ok[i] = 0

while 1:
    s = str(n)
    fin = 1
    for c in s:
        fin &= ok[int(c)]
    if fin:
        print(s)
        exit()
    n += 1

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, D):
    D = set(map(str, D))
    i = N
    while True:
        n = [c for c in str(N)]
        if all(map(lambda x: x not in D, n)):
            return N
        N += 1



def main():
    N, K = read_int_n()
    D = read_int_n()
    print(slv(N, K, D))


if __name__ == '__main__':
    main()

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

while True:
    if any([c in D for c in str(N)]):
        N += 1
    else:
        print(N)
        break

Solution (Python):
N, K = map(int, input().split())
D = list(map(str, input().split()))
while True:
    flg = True
    num = str(N)
    for i in range(len(num)):
        if num[i] in D:
            flg = False
            break
    if flg is True:
        print(int(num))
        break
    N += 1

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

N, K = [int(x) for x in input().split()]
D = [str(x) for x in input().rstrip().split()]
D = set(D)
for i in range(N, N + 10 ** 6):
    i_list = list(str(i))
    flag = 1
    for j in i_list:
        if j in D:
            flag = 0
            break
    if flag:
        print(i)
        sys.exit()

Solution (Python):


import itertools
N, K = input().split()
P = input().split()


a= sorted(set([str(i) for i in range(10)])-set(P))

b1 = itertools.product(a, repeat=len(N))

b2 = itertools.product(a, repeat=len(N)+1)
ans=str()
cnt=0
for i in b1:
  
  ans = "".join(i)
  if N <= ans:
    print(ans)
    cnt=1
    break
if cnt==0:
  for i in b2:
    ans = "".join(i)
    
    if "0"+N <= ans:
      print(ans)
      break

Solution (Python):
n,k=map(int,input().split())
D=set(map(str,input().split()))
for i in range(n,10*n):
    num=set(list(str(i)))
    if i>=n and len(D&num)==0:
        print(i)
        exit()

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

for i in range(n,10*n):
    num=set(list(str(i)))
    if i>=n and len(D&num)==0:
        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):
    num=set(list(map(int,str(i))))
    if i>=n and len(D&num)==0:
        print(i)
        exit()

Solution (Python):
import itertools

N, L = map(str, input().split())
P = list(map(str, input().split()))

U = itertools.product(sorted(list(set([str(i) for i in range(10)])-set(P))),repeat=len(N))
F = itertools.product(sorted(list(set([str(i) for i in range(10)])-set(P))),repeat=len(N)+1)
K = str()
cnt=0
for i in U:
	
	K = ''.join(i)
	if int(K)>=int(N):
		cnt = 1
		print(K)
		break

if cnt == 0:
    for j in F:
        K=''.join(j)
        
        if int(K)>=int(N):
            print(K)
            break

Solution (Python):
N, K = map(int, input().split())
hate = set(map(str, input().split()))
Nos = {str(i) for i in range(10)}
while not set(list(str(N))) & hate == set():
  N += 1
print(N)

Solution (Python):
N, K = map(int, input().split())
hate = set(map(str, input().split()))
Nos = {str(i) for i in range(10)}
available = Nos ^ hate
while not set(list(str(N))) <= available:
  N += 1
print(N)

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

minN = -1
for i in range(n,10*n+1):
  for j in range(len(str(i))):
    if dList.count(int(str(i)[j])) == 0:
      minN = i
    else:
      minN = -1
      break
  if minN != -1:
    break

print(minN)

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

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

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


    while True:
        s = set(list(str(N)))
        if len(s & D) == 0:
            print(N)
            break

        else:
            N+=1
main()

Solution (Python):
N,K = map(int,input().split())
D = input().split()
num = set([str(i) for i in range(10)])
Ds = set(D)
diff = num^Ds
ans = N
while True:
    strN = set(list(str(ans)))
    if strN - diff:
        ans += 1
    else:
        break
print(ans)

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

for i in range(N, 100000):
    str_i = str(i)
    if any([d in str_i for d in dislikes]):
        continue
    print(i)
    break

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
dic={}
for i in d:
    dic[str(i)]=1



while 1:
    s=str(n)
    
    for i in range(len(s)):
        if s[i] in dic:
            break
    else:
        print(n)
        break
    n+=1

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

for i in range(N, 10**5):
	for c in str(i):
		if c in D:
			break
	else:
		print(i)
		exit()

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

for i in range(N, 10**5):
	for c in str(i):
		if c in D:
			break
	else:
		print(i)
		exit()

Solution (Python):
nk=list(map(int,input().split()))
d=list(map(int,input().split()))
i=nk[0]
ans=0
while ans==0:
  flag=0
  for j in range(len(str(i))):
    if int(str(i)[j]) in d:
      flag=1
      break
  if flag==0:
    ans=i
  i+=1
print(ans)

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

while True:
    p = str(n)
    flag = True
    for c in p:
        if c in d:
            flag = False
    if flag:
        print(n)
        break
    else:
        n += 1

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

def ok(i):
  while i > 0:
    k = i%10
    if k in d:
      return False
    i //= 10
  return True


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

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

while True:
    A=str(N)
    count = 0
    for i in range(len(A)):
        if A[i] in D:
            N+=1
            break
        else:
            count +=1
            if count == len(A):
                print(N)
                exit()

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

for i in range(N, 10 * N + 1):
  A = list(map(int, str(i)))
  flag = 1
  for a in A:
    if a in D:
      flag = 0
      break
  if flag:
    print(i)
    exit()

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,10*n):
    a=str(i)
    b=len(a)
    ans=True
    for j in a:
        if j in d:
            ans=False
            break 
    if ans:
        print(i)
        exit()

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

while True:
    flag = True
    for i in str(n):
        if i in d:
            flag = False
    if flag:
        print(n)
        exit()
    n += 1

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

while True:
    if set(list(str(N))) & D:
        N += 1
    else:
        print(N)
        exit()

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

for i in range(N, 10**5):
    for c in str(i):
        if c in D:
            break
    else:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
E = [x for x in range(10) if x not in D]


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

ans = N
while not is_valid(ans):
    ans += 1

print(ans)

Solution (Python):


import numpy as np
import fractions as fra



n,k=map(int,input().split())
d =[x for x in input().split()]

def che(s):
    for x in s:
        for y in d:
            if(x==y):
                return 0
    return 1


for i in range(n,10**10):
    if(che(str(i))):
        print(i)
        exit(0)

Solution (Python):
import sys
from copy import copy


N, K, *D = map(int, open(0).read().split())


candidate = sorted(list({i for i in range(10)} - set(D)))
like_integer = copy(candidate)
  

for j in candidate:
  if j >= N:
    print(j)
    sys.exit()
    
for i in range(1, 6):  
  order = 10 ** i
  
  
  _candidate = []
  for l in like_integer:
    for c in candidate:
      lc = order * l + c
      if lc >= N:
        print(lc)
        sys.exit()
      _candidate.append(lc)
  candidate = _candidate

Solution (Python):



def main():
    N,K = map(int,input().split())
    D = list(map(int,input().split()))
    
    use = []
    for i in range(10):
        if i not in D:
            use.append(i)

    nl = []
    for i in range(N,10*N+1):
        num = i
        ans = True
        while num != 0:
            re = num%10
            num //= 10
            if re not in use:
                ans = False
        if ans:
            print(i)
            exit()
    
if __name__ == "__main__":
    main()

Solution (Python):

def ok():
  for i in str(n):
    if int(i) in d:
      return False
  return True

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

while True:
  if ok():
    break
  n+=1

print(n)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

i = N
while 1:
    s = str(i)
    for a in A:
        if s.count(str(a)):
            break
    else:
        print(i)
        exit()
    i += 1

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
use = [str(i) for i in range(10) if i not in d]
mon5 = [int(i+j+k+l+m) for i in use for j in use for k in use for l in use for m in use if int(i+j+k+l+m)>=n]

mon4 = [int(i+j+k+l) for i in use for j in use for k in use for l in use if int(i+j+k+l)>=n]

mon3 = [int(i+j+k) for i in use for j in use for k in use if int(i+j+k)>=n]

mon2 = [int(i+j) for i in use for j in use if int(i+j)>=n]

mon1 = [int(i) for i in use if int(i)>=n]

print(min(mon1+mon2+mon3+mon4+mon5))

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

set_num = set()
for i in range(10):
    set_num.add(i)

set_use_num = set_num - set_D
set_use_num = sorted(set_use_num)


for j in range(n, 88889):
    Check = True
    for num in str(j):
        if int(num) not in set_use_num:
            Check = False
    if Check:
        ans = j
        break
    else:
        continue

print(ans)

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

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

ni = int(n)

f = []
while True:
	for j in range(len(d)):
		if d[j] not in n:
			f.append(True)
		else:
			f.append(False)
	if False not in f:
		break
	f = []
	ni += 1
	n = str(ni)

print(ni)

Solution (Python):
n,k = map(int,input().split())
d = input().split()
x = n-1
while True:
	x += 1
	s = str(x)
	f = 0
	for t in d:
		if t in s:
			f = 1
	if f == 0:
		print(x)
		break

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
for i in range(N,100000):
    j = i
    while j > 0:
        if j % 10 in D:
            break
        j = int(j/10)
    if j == 0:
        break
print(i)

Solution (Python):




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


def is_inD(n: int):
    tmp = set(str(n))
    return tmp.isdisjoint(D)


for i in range(N, N + 10 ** 6):
    if is_inD(i):
        print(i)
        exit()

Solution (Python):

N, M = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N,100000):
    j = i
    while j > 0:
        if j % 10 in D:
            break
        j = int(j/10)
    if j == 0:
        break
print(i)

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

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

print(N)

Solution (Python):
money, num = map(str, input().split())
hate = list(map(str, input().split()))

for i in range(int(money), 100000):

    a = [hate_num for hate_num in hate if hate_num in str(i)]
    if a == []:
        print(str(i))
        break