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



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Accepted

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

for i in range(N, 10 * N + 1):
    for s in str(i):
        if int(s) in D:
            break
    else:
        print(i)
        quit()

Submission status: Accepted

Solution code:
#C問題
N, K = map(int, input().split())
D = list(map(str, input().split()))

def check(n, d):
    n = str(n)
    for nstr in n:
        if nstr in d:
            return False
    return True
while True:
    if check(N, D):
        print(N)
        break
    else:
        N += 1

Submission status: Accepted

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

n=N
while True:
    queue=0
    nstr=str(n)
    for i in nstr:
        if i in D:
            queue=1
    if queue==0:
        print(n)
        break
    n+=1

Submission status: Accepted

Solution code:
def get_greater_equals(number, target, exclude_digits):
    if number >= target:
        return number
    results = []
    for i in range(10):
        if not i in exclude_digits:
            if i == 0 and number == 0:
                continue
            results.append(
                get_greater_equals(number * 10 + i, target, exclude_digits))
    return min(results)


def main():
    n, k = [int(x) for x in input().rstrip().split(" ")]
    exclude_digits = [int(x) for x in input().rstrip().split(" ")]

    result = get_greater_equals(0, n, exclude_digits)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
 
white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))
 
white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.product(white_num_list, repeat = len(str(N))))
 
num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
    
num_list = sorted(num_list)
 
def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    placeholder = str(min(white_num_list)) * (len(str(N)) + 1)
    if placeholder[0] == '0':
        white_num_list.remove(0)
        placeholder = str(min(white_num_list)) + placeholder[1:]
    return int(placeholder)
      
print(price(N, num_list, white_num_list))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(input().split())
while not all([n not in D for n in str(N)]):
    N += 1
print(N)

Submission status: Accepted

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

Submission status: Accepted

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

flag = False
for a in range(N, 10*N):
	ans = list(str(a))
	for b in range(len(ans)):
		if ans[b] in D:
			break
		if b == len(ans) - 1 and ans[b] not in D:
			print(a)
			flag = True
	if flag:
		break

Submission status: Accepted

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

flag = False
for a in range(N, 10*N+1):
	ans = list(str(a))
	for b in range(len(ans)):
		if ans[b] in D:
			break
		if b == len(ans) - 1 and ans[b] not in D:
			print(a)
			flag = True
	if flag:
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split(' '))
d_list = input().split(' ')
for h in range(10):
    for i in range(10):
        for j in range(10):
            for k in range(10):
                for l in range(10):
                    number = h * 10000 + i * 1000 + j * 100 + k * 10 + l
                    result = set(list(str(number)))
                    if set(d_list) & result != set():
                        continue
                    if number >= N:
                        print(number)
                        break
                else:
                    continue
                break
            else:
                continue
            break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

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

for i in range(N, 10*N+1):
    sn = str(i)
    flg = True
    for c in sn:
        if c in D:
            flg = False
            break
    if flg:
        print(i)
        break

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = set(map(str,input().split()))
def check(n,d):
    n = str(n)
    for nstr in n:
        if nstr in d:
            return False
    return True
while True:
    if check(N,D):
        print(N)
        break
    else:
        N = N+1

Submission status: Accepted

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

for n in range(N, 100000):
  s = str(n)
  for d in D:
    if d in s:
      break
  else:
    print(s)
    break

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D={int(i) for i in input().split()}

C = {0,1,2,3,4,5,6,7,8,9} - D
A=[]
for i in range(9*N+1):
    if (N+i)%10 in C:
        if ((N+i)%100)//10 in C:
            if ((N+i)%1000)//100 in C:
                if ((N+i)%10000)//1000 in C:
                    if (N+i)//10000 in C:
                        A.append(N+i)
                    elif (N+i)//10000==0:
                        A.append(N+i)
                elif (N+i)//1000==0:
                    A.append(N+i)
            elif (N+i)//100==0:
                A.append(N+i)
        elif (N+i)//10==0:
            A.append(N+i)



print(min(A))

Submission status: Accepted

Solution code:
import sys
N, K = map(int, input().split())


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

num_set = set([1,2,3,4,5,6,7,8,9,0])
enable = num_set - d_set
#print(type(enable))
#print(enable)


def dfs(s):
  #print(s)
  global ans
  # すでにN以上の場合はこの先を探索しない
  if s != "":
    if int(s) >= N:
      #print(s)
      ans.append(int(s))
      return

  for num in enable:
    if len(s) == 0 and num == 0:
      continue
    else:
      (dfs(s+str(num)))
    
  return

ans = []
dfs("")
#print(ans)
print(min(ans))

Submission status: Accepted

Solution code:
def main():
	N, K = map(int, input().split())
	D = list(map(int, input().split()))
	rec = 0
	rec2 = 1
	for d in D:
		if rec != d:
			break
		rec += 1
	for d in D:
		if rec2 != d:
			break
		rec2 += 1

	strN = str(N)
	carry = False
	ans = ""
	for i in range(len(strN)-1, -1, -1):
		cur = int(strN[i])
		chanegd = False
		if carry:
			cur += 1
			carry = False
			chanegd = True
			if cur == 10:
				carry = True
		while cur in D:
			cur += 1
			chanegd = True
			if cur == 10:
				cur = 0
				carry = True
		if carry:
			ans = str(rec)*(len(strN)-i)
		else:
			if chanegd:
				ans = str(rec)*(len(strN)-i-1)
			ans = str(cur)+ans
	if carry:
		ans = str(rec)*(len(strN))
		if rec == 0:
			ans = str(rec2) + ans
		else:
			ans = str(rec) + ans

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
s = list(map(int, input().split()))

x = N
while set(list(str(x))) & set(list(str(s))):
    x += 1
    continue
else:
    print(x)

Submission status: Accepted

Solution code:
def task_c():
    """
    https://atcoder.jp/contests/abc042/tasks/abc042_c
    """
    n, k = map(int, input().split())
    dd = input().split()

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

    
task_c()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

pay = n
disLike = True

while disLike:
    disLike = False
    for j in range(len(str(pay))):
        if str(pay)[j] in nums:
            disLike = True
            pay += 1

print(pay)

Submission status: Accepted

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

import sys

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ng = set(input().split())
while len(set(str(n))&ng):
    n+=1
print(n)

Submission status: Accepted

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

for i in range(N, 100000):
    j = str(i)
    more = False
    for k in D:
        if j.count(k) > 0:
            more = True
            break
    if not more:
        ans = i
        break

print(ans)

Submission status: Accepted

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

result = N - 1


def hasNum(result, l):
    for num in l:
        if num in str(result):
            return False

    return True


while True:
    result = result + 1

    if hasNum(result, l):
        print(result)
        break

Submission status: Accepted

Solution code:
N,_ = map(int,input().split())
lists=list(map(str,input().split()))

for i in range(N,100000):
    flg=True
    for j in str(i):
        if j in lists: 
            flg = False
            break
    if flg:
        print(i)
        break

Submission status: Accepted

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

num = N
while True:
    tmp = str(num)
    if all(i not in D for i in tmp):
        break
    num += 1

print(num)

Submission status: Accepted

Solution code:

def read_input():
    n, k = map(int, input().split())
    dlist = list(map(int, input().split()))

    return n, k, dlist


def check_inclusion(dislike, target):
    return any(d in target for d in dislike)


def submit():
    n, k, dlist = read_input()

    target = n
    checkee = [int(digit) for digit in str(target)]

    while check_inclusion(dlist, checkee):
        target += 1
        checkee = [int(digit) for digit in str(target)]

    print(target)

if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ok = set(input().split())
while len(set(str(n))&ok):
    n+=1
print(n)

Submission status: Accepted

Solution code:
N, _ = map(int, input().strip().split())
D = input().strip().split()
for ans in range(N, 100000):
    if len(set(str(ans)) & set(D)) == 0:
        print(ans)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
m=list(map(int,input().split()))
for i in range(n,100000):
  k=1
  for a in str(i):
    if int(a) in m:
      k=0
  if k:
    print(i)
    break

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = input().split()
for i in range(N, 10*N+1):
  for j in str(i):
    if j in D:
      break
  else:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import sys
from itertools import product

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

    nums = set([str(i) for i in range(10)])
    safe = sorted(list(nums - set(D)))
    min_safe = safe[0]
    if min_safe == '0':
        min_safe = safe[1]

    digit = len(str(N))
    safe_num = list(product(safe, repeat=digit))
    ans = 10**5
    for n in safe_num:
        m = int(''.join(n))
        l = int(min_safe + ''.join(n))
        if m >= int(N):
            ans = min(ans, m)

        if l >= int(N):
            ans = min(ans, l)


    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(str,input().split()))
for i in range(n,10*n):
    ans = 0
    for j in str(i):
        if not j in d:
             ans += 1
    if ans==len(str(i)):
        print(i)
        exit()

Submission status: Accepted

Solution code:
def check(x,sample):
    x=str(x)
    for i in x:
        if i in sample:
            return False
    return True

def main():
    n,k=map(int,input().split())
    sample=input().split()
    while 1:
        if check(n,sample):
            print(n)
            return;
        n+=1
main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
def solve(N, K, D):
    i = 0
    while(True):
        test = N + i
        test_str = str(test)
        
        for j in range(K):
            index = -1
            index = test_str.find(D[j])
            if(index>=0):
                break
        if(index == -1):
            break
        i += 1
    print(test)
    
if __name__ == '__main__':
    N, K = map(int, input().split())
    D = [str(d) for d in input().split()]
    
    solve(N, K, D)

Submission status: Accepted

Solution code:
import itertools
n,k=map(int,input().split())
D=list(map(int,input().split()))
N=set(i for i in range(10))
C=list(N-set(D))
ans=float("inf")
for a in list(itertools.product(C,repeat=len(str(n)))):
  m=int("".join(map(str,a)))
  if m>=n:
    ans=min(ans,m)
if ans==float("inf"):
  for a in list(itertools.product(C,repeat=len(str(n))+1)):
    m=int("".join(map(str,a)))
    if m>=n:
      ans=min(ans,m)
print(ans)

Submission status: Accepted

Solution code:
n=int(input().split()[0])
d=set(input())
while set(str(n))&d:
    n+=1
print(n)

Submission status: Accepted

Solution code:
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)
ans = ''

for n in list(map(int, list(str(N)))):
    if n > use[-1]:
        ans+=str(use[0])
    else:
        for i in use:
            if i >= n:
                ans+=str(i)
                break

if str(N)[0] < ans[0]:
    ans = ans[0]+str(use[0])*(len(ans)-1)

if N-int(ans) > 0:
    ans = str(use[0]) + str(use[0])*len(str(N)) if use[0]!=0 else str(use[1])+str(use[0])*len(str(N))



print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())  # 標準入力
D = map(int, input().split())  # 嫌いな数字のリスト
D_str = list(map(str, D))
m = N
 
while True:
    for n in str(m):
        if n in D_str:
            break
    else: # breakされなかったら実行される
        print(m)
        break
    m += 1

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
d = nl()
for i in range(n, 100001):
    lis = list(str(i))
    f = 0
    for j in lis:
        if int(j) in d:
            f = 1
    if f == 0:
        print(i)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())  # 標準入力
D = map(int, input().split())  # 嫌いな数字のリスト
D_str = list(map(str, D))
m = N

while True:
    for n in str(m):
        if n in D_str:
            break
    else: # breakされなかったら実行される
        print(m)
        break
    m += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D=input()
D_str=str(D)
i=0
string=D_str.split()
while True:
    judge=0
    fee=n+i
    fee_str=str(fee)
    for j in range(k):
        index=fee_str.find(string[j])
        judge = judge + index
    if judge == -k :
        break
    i=i+1
print(fee)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=[int(i) for i in input().split()]
t=n
while 1:
    x=t
    while 1:
        if x%10 in d:
            break
        else:
            x//=10
        if x==0:
            print(t)
            exit()
    t+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
dislike = list(input().split())

while True:
    M = str(N)
    numbers = list(M)
    matchedlist = []
    for a in dislike:
        for b in numbers:
            if a == b:
                matchedlist.append(a)
    
    if matchedlist == []:
        break

    N += 1

print(N)

Submission status: Accepted

Solution code:
n, k = (int(_) for _ in input().split())
a = [int(_) for _ in input().split()]

found = False
bad = False
while not found:
    for i in str(n):
        if int(i) in a:
            bad = True
    if not bad:
        found = True
    bad = False
    n += 1

print(n - 1)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    f = True

    for a in map(int, list(str(n))):
        if a in dl:
            f = False

    if f:
        break
    n += 1

print(n)

Submission status: Accepted

Solution code:
import bisect
n,k=map(int,input().split())
l=list(map(int,input().split()))
nl=list(range(10))
for i in l:nl.remove(i)
ch=int(str(nl[-1])*len(str(n)))<n
if ch and nl[0]==0:
    print(int(str(nl[1])+"0"*(len(str(n)))))
elif ch:
    print(int(str(nl[0])*(len(str(n))+1)))
else:
    ans=""
    for i in range(len(str(n))):
        if int(str(n)[i]) in l:
            ans+=str(nl[bisect.bisect_left(nl,int(str(n)[i]))])
            ans+=str(nl[0])*(len(str(n))-i-1)
            break
        else:ans+=str(n)[i]
    print(ans)

Submission status: Accepted

Solution code:
# 0〜9
l=list(range(10))

# 入力
N,K=map(int,input().split())
l2=list(map(int,input().split()))

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# 集合型に変換
l=set(l)

# 1<=N<=10000 なので、答えは最大でも100000まで
for x in range(1,100001):
  # 集合型に変換
  y=set(map(int,list(str(x))))

  # Nを上回る数字かつ、使える数字のみを使用している場合
  if N<=x and l.issuperset(y):
    print(x)
    break

Submission status: Accepted

Solution code:
# 0〜9
l=list(range(10))

# 入力
N,K=map(int,input().split())
l2=list(map(int,input().split()))

ans=''
f=False

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# 集合型に変換
l=set(l)

for x in range(1,1000000):
  y=set(map(int,list(str(x))))
  if N<=x and l.issuperset(y):
    print(x)
    break

Submission status: Accepted

Solution code:
import collections
import math
import sys
N,K = map(int,input().split())
Ds = list(map(int,input().split()))
for n in range(N,100000):
    check = True
    for d in Ds:
        if str(d) in str(n):
            check = False
            break
    if check ==True:
        print(n)
        break

Submission status: Accepted

Solution code:
def f(n, d):
    while True:
        for x in d:
            try:
                str(n).index(str(x))
            except ValueError:
                pass
            else:
                break
        else:
            return n
        n = n + 1


nk = list(map(int, input().split()))
n = nk[0]

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

print(f(n, d))

Submission status: Accepted

Solution code:
n, _ = map(int, input().split(' '))
no_likes = list(map(int, input().split(' ')))

numbers = sorted([i for i in range(10) if i not in no_likes])

for i in range(n, 100000):
    for b in str(i):
        if int(b) not in numbers:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in range(Num[0],100000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(int(i))
        break

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
d_li = [int(i) for i in input().split()]
all_digits = set(range(10))
dis_digits = set(d_li)
like_digits = all_digits - dis_digits
like_li = sorted(list(like_digits))

while set([int(i) for i in str(N)]) & dis_digits:
    N += 1
print(N)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(list(map(int, input().split())))
while True:
    int_i = [int(s) for s in list(str(N))]
    set_i = set(int_i)
    if not D & set_i:
        print(N)
        break
    N += 1

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
l1=map(int,input().split())
l2=[0,1,2,3,4,5,6,7,8,9]
l3=set(l1)^set(l2)
m=str(n)
l4=map(int,set(m))
l4=set(l4)
def check(a,b):
    if (a|b)==a:
        return True
    else:
        return False
while check(l3,l4) is False:
    n=n+1
    m=str(n)
    l4=map(int,set(m))
    l4=set(l4)
print(n)

Submission status: Accepted

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

#使用可能数字の取り出し
Num1 = []
for i in range(10):
  if(i in D): continue
  else: Num1.append(i)
 
#組み合わせ
Comb = []
n = len(str(N))
for i in range(n+1):
  Comb.append(Num1)
Comb = list(itertools.product(*Comb))

ans = -1
for i in range(len(Comb)):
  tmp = Comb[i]
  tmp_num = ''
  for j in range(n): tmp_num += str(tmp[j])
  tmp_num = int(tmp_num)
  if(N <= tmp_num):
    ans = tmp_num
    break
    
if(ans == -1):
  for i in range(len(Comb)):
   tmp = Comb[i]
   tmp_num = ''
   for j in range(n+1): tmp_num += str(tmp[j])
   tmp_num = int(tmp_num)
   if(N <= tmp_num):
     ans = tmp_num
     break
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
j=[(True if i in d else False)for i in range(10)]
for i in range(n,10**6):
    s=str(i)
    for h in range(len(s)):
        if j[int(s[h])]:
            break
    else:
        print(s)
        break

Submission status: Accepted

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

while True:
    for c in str(N):
        if c in list_D:
            break
    else:
        print(N)
        break
    N += 1

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
dl = list(input().split())
# 案１：使える数値を順に組み合わせていく
# 案２：Nから順に数字を＋１ずつ加算していき、使える文字のみになったら終了
temp = N - 1
flg = True
while flg:
    temp += 1
    flg = False
    st = str(temp)
    for i in range(len(st)):
        if st[i] in dl:
            flg = True
print(temp)

Submission status: Accepted

Solution code:
def irohas_obsession(N: int, K: int, D: list) -> int:
    # D に含まれない最小の値
    min_not_d = min(d for d in range(10) if d not in D)
    min_not_d_and_not_zero = min(d for d in range(10) if d not in D and d != 0)

    # 数字を各桁に分解する。
    nums = []
    while N > 0:
        nums = [N % 10] + nums
        N //= 10

    # 上位の桁から見ていって最初に D に含まれる数字を探す。
    convert_idx = -1
    for i, n in enumerate(nums):
        if n not in D:
            # 変換の必要がない
            continue

        convert_idx = i
        break
    # print(convert_idx)
    for i in range(convert_idx, -1, -1):
        n = nums[i]
        if n > 9:
            n %= 10
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

        for d in range(n, 10):
            # 変換先が n 以上 9 以下
            if d in D:
                # NG
                continue

            nums[i] = d
            break
        else:
            # 変換先が n 未満
            for d in range(n, 10):
                if d in D:
                    # NG
                    continue

                nums[i] = d

            # 上位の桁に繰り上がりを伝搬
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

    # 残りの桁は D に含まれない最小の値に変換する。
    nums = [min_not_d if n in D else n for n in nums]

    ret = 0
    digit = 1
    # print(nums)
    for n in reversed(nums):
        ret += n * digit
        digit *= 10

    return ret


if __name__ == "__main__":
    N, K = map(int, input().split())
    D = [int(s) for s in input().split()]
    ans = irohas_obsession(N, K, D)
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

N, K = map(int, input().split())
D = input().split()
decimal = set(["0","1", "2", "3", "4", "5", "6", "7", "8", "9"]) - set(D)
candidate = []
def dfs(s):
    if len(s) == 0:
        sub_d = decimal - set("0")
        for d in sub_d:
            dfs(s + d)    
    elif len(s) < len(str(N)) + 1:
        if int(s) >= N:
            candidate.append(int(s))
        for d in decimal:
            dfs(s + d)
    else:
        candidate.append(int(s))
        return
dfs("")
print(sorted(candidate)[0])

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

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

while True:
    res = n
    for x in d:
        res = str(res).replace(str(x), "X")
    if "X" in res:
        n += 1
    else:
        print(res)
        exit()

Submission status: Accepted

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

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

ans = []
t = 0
for i, dig in enumerate(list(str(N))):
    m = 10
    for cu in can_use:
        sa = cu - int(dig)
        if sa <= m and sa >= 0:
            m = sa
            ans.append(cu)
            if abs(len(list(str(N)))-1-i) == 0:
                break
            t += cu*10**abs(len(list(str(N)))-1-i)
            tmp = t + int(str(can_use[0])*abs(len(list(str(N)))-1-i))
            if tmp >= N:
                print(tmp)
                exit()



# for dig in list(str(N))[::-1]:
#     m = 10
#     for cu in can_use:
#         sa = cu - int(dig)
#         if sa <= m and sa >= 0:
#             m = sa
#             ans.append(cu)

if len(ans) < len(list(str(N))):
    min_not0 = can_use[1] if can_use[0] == 0 else can_use[0]
    print(str(min_not0)+str(can_use[0])*len(list(str(N))))
    exit()

print(''.join(map(str, ans[::-1])))
# print(''.join(map(str, ans[::-1])))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,10**6):
  flag=True
  for j in str(i):
    if int(j) in d:
      flag=False
      break
  if flag:
    print(i)
    exit()

Submission status: Accepted

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

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

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

for i in range(n,100000):
    if set([int(a) for a in str(i)])|X==X:
        print(i)
        break

Submission status: Accepted

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

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

n_list = list(str(n))
n_list = [int(num) for num in n_list]

num = {1,2,3,4,5,6,7,8,9,0}

d_set = set(d)
empty = set()
#print(set(n_list))
#print(d_set)
#print(set(n_list) & d_set)
while(1):
  n_list = list(str(n))
  n_list = [int(num) for num in n_list]
  if(set(n_list) & d_set == empty):
    print(n)
    break
  n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,88889):
  for j in list(str(i).replace(""," ").split()):
    if j in d:
      break
  else:
    print(i)
    break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,90000):
  for j in list(str(i).replace(""," ").split()):
    if j in d:
      break
  else:
    print(i)
    break

Submission status: Accepted

Solution code:
#C問題  
N,K=map(int,input().split())
D=list(map(str,input().split()))
for i in range(10*N):
    Nlist=list(str(N))
    Nlen=len(Nlist)
    flag=0
    for j in range(Nlen):
        if Nlist[j] in D:
            flag=1
            break
    if flag == 0:
        print(int(N))
        break
    N+=1

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
N, K = [int(x) for x in input().rstrip().split()]
D = [int(x) for x in input().rstrip().split()]
ok = [x for x in range(10) if x not in D]
tmp = N
while 1:
	for y in str(tmp):
		if int(y) in ok:
			pass
		else:
			break
	else: # すべて使用可能
		print(tmp)
		break
	tmp += 1

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
d=""
e=0
for i in range(100000):
  d=str(n+i)
  for j in range(k):
    e=e+d.count(str(a[j]))
  if e==0:
    print(int(d))
    break
  e=0

Submission status: Accepted

Solution code:
n,k=map(int,input().split());d=input().split()
def judge():
  global d,n
  for i in str(n):
    if i in d:return
  print(n)
  exit()
while 1:
  judge()
  n+=1

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 一文字のみを読み込み
    # s = input().rstrip().split(' ')
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 位置文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    slist = input().rstrip().split(' ')
    N = int(slist[0])
    K = int(slist[1])
    D = input().rstrip().split(' ')

    for n in range(N,100000):
        # 各桁にDの配列にある数値がいるか
        d_flag = False
        tmp_n = list(str(n))
        # print(tmp_n)
        for tmp_char in tmp_n:
            if (str(tmp_char) in D):
                d_flag = True
                break
        if(d_flag == False):
            print(n)
            break
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n,n*100):
    flg=True
    for j in str(i):
        if j in d:
            flg=False
            break;

    if flg:
        print(i)
        break

Submission status: Accepted

Solution code:
import itertools
import bisect


def main():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    P = [str(x) for x in range(10) if x not in D]
    num = []
    for i in range(1, len(str(N))+2):
        for c in itertools.product(P, repeat=i):
            num.append(int("".join(c)))
    idx = bisect.bisect_left(num, N)
    print(num[idx])


if __name__ == "__main__":
    main()