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):
def check(n, D):
    N = []
    while n != 0:
        N.append(n % 10)
        n //= 10
    for d in D:
        if d in N:
            return False
    return True

if __name__ == '__main__':
    n, k = [int(x) for x in input().split(' ')]
    D = [int(x) for x in input().split(' ')]
    res = n
    while True:
        if check(res, D):
            break
        else:
            res += 1
    print(res)

Solution (Python):
n,k = map(int,input().split())
d = list(map(str,input().split()))
while True:
  sn = str(n)
  l = len(sn)
  flag = True
  for i in range(l):
    if sn[i] in d:
      flag = False
      break
  if flag:
    print(n)
    exit()
  n += 1

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

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

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

Solution (Python):
N,K=map(int,input().split())
*D,=input().split()
ok=1
while ok:
    ans=list(str(N))
    ok=0
    for a in ans:
        if a in D:
            ok=1
    N+=1
print(''.join(ans))

Solution (Python):
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools, heapq
ans = []
heapq.heapify(ans)
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        heapq.heappush(ans, s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            heapq.heappush(ans, s)
    print(heapq.heappop(ans))
    
else:
    print(heapq.heappop(ans))

Solution (Python):
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools
ans = []
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        ans.append(s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            ans.append(s)
    print(min(ans))
    
else:
  print(min(ans))

Solution (Python):
import sys
from itertools import product
def input(): return sys.stdin.readline().strip()

def main():
    """
    itertools.productを使うと高速なようなので写経
    参考：https://atcoder.jp/contests/abc042/submissions/16188969
    """
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    l = len(str(N))
    if int(str(ok[-1]) * l) < N:
        if ok[0] == 0:
            print(ok[1] * 10 ** l)
        else:
            print(str(ok[0]) * (l + 1))
    else:
        for x in product(ok, repeat=l):
            x = int("".join(map(str, x)))
            if x >= N:
                print(x)
                return



if __name__ == "__main__":
    main()

Solution (Python):
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    while True:
        check = True
        for c in str(N):
            if int(c) in D:
                check = False
        if check:
            print(N)
            return
        N += 1


if __name__ == "__main__":
    main()

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

ans = str(n)
while not all([c not in D for c in ans]) and int(ans) >= n:
    ans = str(int(ans) + 1)
print(ans)

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

Solution (Python):
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for x in dislike_nums:
    dislikes[x] = True

for n in range(N, N * 10):
    found = False
    for x in str(n):
        if dislikes[int(x)]:
            found = True
            break
    if not found:
        break
print(n)

Solution (Python):
import sys

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


while True:
  for x in [int(n) for n in str(N)]:
    if x in D:
      break
  else:
    print(N)
    sys.exit()
  N+=1

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

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

while True:
    tmp = set(str(N))
    b = True
    for x in tmp:
        if int(x) in D:
            b = False
            break 
    if b == True:
        break
    else:
        N += 1

print(N)

Solution (Python):
def minN(N:int, usable:list, restrict=True):
    usable.sort()
    keta = False
    if restrict:
        for i in usable:
            if i >= N:
                return str(i)
        
        return '1'+str(usable[0])
    else:
        return str(usable[0])

def rote(N:list, D:set, d:set):
    ans = []
    flag = True
    lenNstr = len(N)
    for i, n in enumerate(N):
        n = int(n)
        keta = 10**(len(N) - i - 1)
        if flag:
            if n in D:
                ans.append(int(minN(n, d)) * keta)
                flag = False
            else:
                ans.append(keta * n)
        else:
            ans.append(keta * min(d))
    return sum(ans)

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = list(numset.difference(D))
    d.sort()
    for _ in range(10):
        Nstr = list(str(N))
        ans = rote(Nstr, D, d)
        N = ans    
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = numset.difference(D)

    for n in range(N, pow(10, 6) + 10):
        check = set(list(str(n)))
        ngflag = False
        for i in check:
            if int(i) in D:
                ngflag = True
                break
        if not ngflag:
            break
    print(n)

if __name__ == "__main__":
    main()

Solution (Python):
i3=lambda : map(int,input().split())

N,K=i3()
*D,=i3()

D=set(D)

for i in range(N,10**5):
    ans=1
    for s in str(i):
        if int(s) in D:
            ans=0
            break
    if ans : break
print(i)

Solution (Python):
n,k=map(int,input().split());a=set(input().split())
while True:
  if not set(str(n))&a: print(n);break
  n+=1

Solution (Python):
n,k = input().split()
hate = list(input().split())
exi = True
t = True

while True:
    for c in hate:
        t = True
        if c in list(n):
            t = False
            break
    if t:
        print(n)
        break

    intN = int(n) + 1
    n = str(intN)

Solution (Python):
n, k = map(int, input().split())
D = set(map(int, input().split()))
from itertools import count
for ans in count(n,1):
    for c in str(ans):
        if int(c) in D:
            break
    else:
        print(ans)
        break

Solution (Python):
def dfs(i,num_str):
    global ans_list
    if i==len(str(n)):
        ans_list.append(int(num_str))
        if len(num_list)==1:
            ans_list.append(int(num_list[0]+num_str))
        else:
            if num_list[0]=='0':
                ans_list.append(int(num_list[1]+num_str))
            else:    
                ans_list.append(int(num_list[0]+num_str))
        return
    else:
        for j in num_list:
            dfs(i+1,num_str+j)

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

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


dfs(0,'')
sort_list = sorted(ans_list)


for i in sort_list:
    if n<=i:
        print(int(i))
        break

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

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

for i in range(n,10**5):
    count=0
    for j in range(k):
        u = str(d[j])
        if(str(i).count(u)==0):
            count+=1
    
    if(count==k):
        print(i)
        break

Solution (Python):
n,k=map(int,input().split())
l=list(map(int,input().split()))
for v in range(n,10**5):
    for c in str(v):
        if int(c) in l:
            break
    else:
        print(v)
        exit()

Solution (Python):
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
c = 2
while c in D:
    c += 1
y = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        y = x
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[x]):
        for i in range(len(N)-1-x):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
while y > 0:
    s = ans[y][0]
    t = ans[y][1]
    r = ans[y]
    ans[y] = t
    ans[y-1] = str(int(ans[y-1]) + 1)
    if int(ans[y-1]) in D:
        u = int(ans[y-1])
        while u in D:
            u += 1
            ans[y-1] = str(u)
    if ans[y-1] != "10":
        y = 0
    else:
        y -= 1
        ans[y] = r
print("".join(ans))

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

v = n
while True:
    f = True
    for t in list(str(v)):
        if int(t) in d:
            f = False
            continue
    if f:
        print(v)
        exit(0)
    v+=1

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

def find_ok( x , Oks ):
    for i in Oks:
        if int(i) > int(x):
            break
    return i

def main():
    n,k = map( int , input().split() )
    Nos = set(map( int , input().split() ))
    while(1):
        x = str(n)
        set_n= set()
        for digit in x:
            set_n.add( int(digit) )
        if len(set_n & Nos) == 0:
            break
        n += 1
    print(n)



main()

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
x=list(range(1,100001))
y=[0]*100000
for i in range(100000):
    s=str(i)
    S=len(s)
    for j in range(S):
        if int(s[j]) in d:
            y[i-1]=1
            break
for i in range(100000):
    if i>=n-1:
        if y[i]==0:
            print(i+1)
            break

Solution (Python):
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
D=set(D)
kouho=N
while(1):
    lenkouho=len(str(kouho))
    flag=1
    for i in range(lenkouho):
        if int(str(kouho)[i]) in D:
            flag=0
    if flag==1:
        print(kouho)
        break
    kouho+=1

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

for i in range(N, 10**6+1):
  l = [j for j in str(i)]
  flag = True
  for n in l:
    if int(n) in s:
      flag = False
      break
  if flag:
    ans = i
    break
print(ans)

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

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


for i in range(n,pow(10,5)):
    a=set()
    v=str(i)
    for j in range(len(v)):
        a.add(int(v[j]))

    if a.isdisjoint(d):
        print(i)
        exit()

Solution (Python):





import datetime






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

Solution (Python):
def dfs(A: list):
    if len(A) > nn:
        return
    if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
        ans[0] = x
        return

    for v in d:
        if v == "0" and len(A) == 0:
            next
        A.append(v)
        dfs(A)
        A.pop()


n, k = map(int, input().split())
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
nn = len(str(n))+1
ans = [10**7]
dfs([])
print(ans[0])

Solution (Python):
def dfs(A: list):
    if len(A) > len(str(n))+1:
        return
    if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
        ans[0] = x
        return

    for v in d:
        if v == "0" and len(A) == 0:
            next
        A.append(v)
        dfs(A)
        A.pop()


n, k = map(int, input().split())
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
ans = [10**10]
dfs([])
print(ans[0])

Solution (Python):
import sys


def check(pay, like):
    str_pay = str(pay)
    like = ''.join(like)
    for p in str_pay:
        for lk in like:
            if p == lk:
                return False

    return True

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

D = []
D = list(map(int, input().split()))
str_D = []

for s in D:
    str_D.append(str(s))

pay = N

while True:
    if check(pay, str_D):
        print(pay)
        sys.exit()
    pay += 1

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


while True:
    
    for j in str(n):
        
        if j in a:
            break
    else:
        break
    n += 1        
    
print(n)

Solution (Python):


n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) if u < n else u

print dfs(0,n,letters)

Solution (Python):


n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

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):
total, k = map(int, input().split())

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

def total_to_digits(total):
    return map(int, list(str(total)))

def find_lowest_denomination(total, d):
    res = None
    for i in range(total, 99999):
        digits = list(total_to_digits(i))
        if not (set(digits) & set(d)):
            print(i)
            return


find_lowest_denomination(total, d)

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

for payment in range(N, 10*N+1):
    if all(char not in D for char in str(payment)):
        print(payment)
        break

Solution (Python):




import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)


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

    for i in range(N, 10*N+1):
        for d in D:
            if str(i).count(d) != 0:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    
    resolve()

Solution (Python):




import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)


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

    for i in range(100000):
        if i < N:
            continue
        for d in D:
            if str(i).count(d) != 0:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    
    resolve()

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

inf = float('inf')
min_cost = inf
for amount in range(n, 100000):
    for i, e in enumerate(arr):
        if str(e) in str(amount):
            break
        if i == len(arr)-1:
            min_cost = min(min_cost, amount)

print(min_cost)

Solution (Python):
'''
Created on 2020/08/25

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,K=map(int,pin().split())
  D=list(map(int,pin().split()))



  j=N
  while True:
    for k in str(j):
      if int(k) in D:
        break
    else:
      print(j)
      break
    j+=1
  return 
main()

Solution (Python):
N, K = map(int, input().split())
A = set(map(int, input().split()))
while 1:
  B = set(map(int, list(str(N))))
  if len(A & B) == 0:
    print(N)
    break
  N += 1

Solution (Python):
N,K,*dd = map(int, open(0).read().split())

valid = [1] * 10
for d in dd:
    valid[d] = 0
digits = [i for i,v in enumerate(valid) if v]
num_digit = len(str(N))

from itertools import product
from sys import exit
for ans_digit in [num_digit, num_digit+1]:
    for x in product(digits, repeat=ans_digit):
        x = int(''.join(map(str, x)))
        if x >= N:
            print(x)
            exit()

Solution (Python):
from itertools import combinations_with_replacement
n, k = map(int, input().split())
d = [int(x) for x in input().split()]
dd = set(list(range(10))) - set(d)

x = str(n)
lst = []
dd = list(dd)
dd.sort()
sel = []
for i in dd:
    if int(x[0]) <= i and len(sel) < 3: sel.append(i*10**(len(x)-1))
if len(sel) < 2:
    if len(dd) == 1:
        sel.append((dd[0]*10 + dd[0])* 10 ** (len(x)-1))
    else:
        if dd[0] != 0:
            sel.append((dd[0]*10 + dd[0])* 10 ** (len(x)-1))
        else:
            sel.append((dd[1]*10 + dd[0])* 10 ** (len(x)-1))
for j in sel:
    for l in combinations_with_replacement(dd, len(x)-1):
        cnt = j
        for i in range(len(x)-1):
            cnt += 10 ** (len(x)-i-2) * l[i]
        if cnt >= n: lst.append(cnt)
print(min(lst))

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

while True:
    s = str(n)
    flag = True
    for c in s:
        if c in d:
            flag = False
    
    if flag:
        print(n)
        break

    n += 1

Solution (Python):
nk = list(map(lambda x: int(x), input().split(" ")))
n = nk[0]
k = nk[1]

ds = input().split(" ")

res = n
while True:
    is_ok = [str(res).find(d) == -1 for d in ds]
    if all(is_ok):
        break
    else:
        res = res + 1

print(res)

Solution (Python):
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,K=MAP()
L=list(input().split())
L=set(L)
for i in range(N,100000):
  if set(str(i))&L==set():
    print(i)
    exit()

Solution (Python):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


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

while True:
    if all(int(j) not in d for j in str(n)):  
        print(n)
        exit()
    n += 1

Solution (Python):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


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

while True:
    if all([int(j) not in d for j in str(n)]):  
        print(n)
        exit()
    n += 1

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

can_use = []
for i in range(10):
    if (i in D):
        continue
    else:
        can_use.append(i)


while True:
    str_N = str(N)
    flag = True
    for i in range(len(str_N)):
        if int(str_N[i]) in D:
            N += 1
            flag = False
            break
        else:
            continue
    if flag:
        break

print(N)

Solution (Python):
N,K = (int(T) for T in input().split())
D = input().split()
for TN in range(N,100000):
    StrN = str(TN)
    Flag = True
    for TS in StrN:
        if TS in D:
            Flag = False
            break
    if Flag:
        print(TN)
        break

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

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

Solution (Python):
from collections import defaultdict
digit = []
def check(n):
	global digit
	while n:
		rem  = n%10
		for i in digit:
			if i==rem:
				return False
		n = n//10
	return True
def main():
	global digit
	n , k = map(int , input().split())
	digit = list(map(int , input().split()))
	ans = n
	while (check(n))==False:
		n = n+1
	print(n)

if __name__ =="__main__":
	main()

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

while(True):
    x = n
    while(x):
        if x%10 in d:
            break
        x//=10
    else:
        print(n)
        quit(0)
    n += 1

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

for i in range(1,10**5+1):
  if i>=n:
    p=str(i)
    ch=0
    for y in range(len(p)):
      if int(p[y]) in a:
        ch+=1
    if ch==0:
      print(i)
      break

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

flag = True
while True:
    strn = str(n)
    for i in d:
        if i in strn:
            n += 1
            break
    else:
        flag = False
        break

print(n)

Solution (Python):
n, k = [int(x) for x in input().split()]
d_set = set(input().split())
while True:
    if len(set(str(n)).intersection(d_set)) == 0:
        break
    n += 1
print(n)

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

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

Solution (Python):
kingaku, n = input().split()
no_num = input().split()
ok_num = [str(i) for i in range(10) if not str(i) in no_num]
result = []
 
for i in kingaku:
    for j in ok_num:
        if i == j:
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    else:
        n = 1 if ok_num[0] == '0' else 0
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()
 
print(''.join(result))

Solution (Python):
kingaku, n = input().split()
no_num = input().split()
ok_num = [str(i) for i in range(10) if not str(i) in no_num]
result = []
 
for i in kingaku:
    for j in ok_num:
        if i == j:
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    else:
        n = 1 if ok_num[0] == '0' else 0
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()
 
print(''.join(result))

Solution (Python):
kingaku, n = input().split()
no_num = input().split()
ok_num = [str(i) for i in range(10) if not str(i) in no_num]
result = []
 
for i in kingaku:
    for j in ok_num:
        if i == j:
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    else:
        n = 1 if ok_num[0] == '0' else 0
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()
 
print(''.join(result))

Solution (Python):
kingaku, n = input().split()
no_num = input().split()
ok_num = []
result = []

for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))

set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    
    if set_flg:
        n = 0
        if ok_num[0] == '0':
            n = 1
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()

print(''.join(result))

Solution (Python):
kingaku, n = input().split()
no_num = input().split()
result = []
ok_num = []
kuriage_num = [-1, 0]

def kuriage(l):
    for i in ok_num:
        if result[l] < i:
            kuriage_num = [l, i]
            return
    if l <= 0:
        return
    return kuriage(l-1)


for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))

set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    
    if set_flg:
        n = 0
        if ok_num[0] == '0':
            n = 1
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()

print(''.join(result))

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

d = set()
for i in range(K):
    d.add(str(D[i]))


for i in range(N, 100000):
    flag = True
    s = str(i)
    li = list(s)
    for nowletter in li:
        if nowletter in d:
            flag = False
    if flag:
        print(i)
        exit()

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

d = set()
for i in range(K):
    d.add(str(D[i]))


for i in range(N, 100000):
    s = str(i)
    li = list(s)
    nowset = set(li)
    if not nowset & d:
        print(i)
        exit()

Solution (Python):
k,n=map(int,input().split())
l=set(input().split())
for i in range(k,10**6):
    if (set(str(i)).isdisjoint(l)):
        print(i)
        break

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

C = list({0,1,2,3,4,5,6,7,8,9}-D)
C.sort()
num = len(N)

def minimum(x,ans):
    ans += str(min(C))*x
    return ans

ans = ''
if C[-1]<int(N[0]):
    C_0 = list(set(C)-{0})
    ans += str(min(C_0))
    ans = minimum(num,ans)
    print(ans)
    exit()

points = 0
for i in range(0,num):
    minus = 0
    for j in range(len(C)):
        if C[j]==int(N[i]):
            ans += str(C[j])
            points += 1
            break
        elif C[j]>=int(N[i]):
            ans += str(C[j])
            ans = minimum(num-i-1,ans)
            print(int(ans))
            exit()
            points = 0
        else:
            minus += 1
    if points == i and minus == len(C):
        ans = ''
        C_0 = list(set(C)-{0})
        ans += str(min(C_0))
        ans = minimum(num,ans)
        print(ans)
        exit()

print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    D = set(input().split())
    for I in range(N,10**6):
        if set(str(I)).isdisjoint(D):
            print(I)
            break


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
N, K = map(int, input().split())
nums = list(map(str, input().split()))
can_use_nums = set([str(i) for i in range(10)])
for num in nums:
    can_use_nums.remove(num)


queue = deque([[num] for num in can_use_nums if num != '0'])

min_num = float('inf')
while queue:
    num = queue.popleft()
    if N <= int(''.join(num)):
        min_num = min(min_num, int(''.join(num)))
    else:
        for add_num in can_use_nums:
            t_num = num.copy()
            if min_num > int(''.join(num) + add_num):
                t_num.append(add_num)
                queue.append(t_num)
print(min_num)

Solution (Python):
N, _ = input().split()
N = int(N)
dislike = list(map(int, input().split()))
like = []
f = True
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
x = N
for i in l:
    if i not in dislike:
        like.append(i)
like = list(str(like))
dislike = list(str(dislike))
while f:
    x = list(str(x))
    for i in x:
        if i not in dislike:
            f = False
        else:
            f = True
            break
    x = int("".join(x)) + 1

if x != 0:
    x -= 1
print(x)