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: Runtime Error

Solution code:
import bisect
N,K = map(int,input().split())
D = list(map(int,input().split()))
num = {0,1,2,3,4,5,6,7,8,9}
Ds = set(D)
diff = num^Ds
if 0 in diff:
    diff.remove(0)
    lenn = len(str(N))
    print(str(min(diff)) + '0'*(lenn-1))
else:
    lenn = len(str(N))
    diff = list(diff)
    diff.sort()
    strN = str(N)
    for i in range(lenn):
        intN = int(strN[i])
        ind = bisect.bisect_left(diff,intN)
        print(diff[ind],end='')

Submission status: Runtime Error

Solution code:
import os

if __name__ == "__main__":
    temp = input().split(" ")
    N = temp[0]
    L = int(temp[1])
    D = list(map(int, input().split(" ")))
    
    like = []
    for i in range(0, 10):
        if D.count(i) == 0:
            like.append(i)
   
    ans = []
    for n in N:
        for l in like:
            if int(l) >= int(n):
                ans.append(l)
                break
    if int("".join(map(str, ans))) < int("".join(map(str, N))):
        ans = []
        for i in range(0, len(N)):
            ans.append(min(like))
            
    print("".join(map(str, ans)))

Submission status: Runtime Error

Solution code:
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 str(i)[j] in d:
      flag=1
      break
  if flag==0:
    ans=i
  i+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc042/tasks/arc058_a
# 最悪でも10**6探索する程度なのでNを一つづつ足して全探索でもよくね？


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()


# もっとスケーラブルな方法
all_nums = {str(i) for i in range(10)}
use_nums = all_nums - D
N_str = str(N)
L = len(N_str)

ans = []
for l in range(L):
    tmp = []
    for num in use_nums:
        if int(num) >= int(N_str[l]):
            tmp.append(num)
    ans.append(min(tmp))

print(int(''.join(ans)))

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
D=list(map(int,input().rstrip().split()))

def dfs(N):
    for i in range(K):
        if(str(N).find(str(D[i]))!=-1):
            dfs(N+1)
            return
    else:
        print(N)
        return
    return
    


dfs(N)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
D=list(map(int,input().rstrip().split()))

def dfs(N):
    for i in range(K):
        if(str(N).find(str(D[i]))!=-1):
            dfs(N+1)
            return
    else:
        print(N)
        return
    return
    


def resolve():
    dfs(N)


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)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
D=list(map(int,input().rstrip().split()))

def dfs(N):
    for i in range(K):
        if(str(N).find(str(D[i]))!=-1):
            dfs(N+1)
            return
    else:
        print(N)
    
    


def resolve():
    dfs(N)


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)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
n, k = map(int,input().split())
d = list(map(int,input().split()))
ns = str(n)
e = []
for i in range(k):
    if i not in d:
        e.append(i)
f = True
ans_s = ''
for j in range(len(ns)):
    if f:
        for l in range(len(e)):
            if e[l] >= int(ns[j]):
                ans_s += str(e[l])
                if e[l] > int(ns[j]):
                    f = False
                break
    else:
        ans_s += str(e[0])

ans_od = ''
if e[0]==0:
    ans_od += str(e[1])
else:
    ans_od += str(e[0])
for m in range(len(ns)):
    ans_od += str(e[0])

if ans_s != '':
    if int(ans_s)>=n:
        print(int(ans_s))
    else:
        print(int(ans_od))
else:
    print(int(ans_od))

Submission status: Runtime Error

Solution code:
n, k = map(int,input().split())
d = list(map(int,input().split()))
def over_digit():
    ans_d = ''
    if e[0]==0:
        ans_d += str(e[1])
    else:
        ans_d += str(e[0])
    for m in range(len(ns)):
        ans_d += str(e[0])
    return ans_d

ns = str(n)
e = []
for i in range(k):
    if i not in d:
        e.append(i)
f = True
ans_s = ''
for j in range(len(ns)):
    if f:
        for l in range(len(e)):
            if e[l] >= int(ns[j]):
                ans_s += str(e[l])
                if e[l] > int(ns[j]):
                    f_con = False
                break
    else:
        ans_s += str(e[0])
if ans_s != '':
    if int(ans_s)>=n:
        print(int(ans_s))
    else:
        ans = int(over_digit())
        print(ans)
else:
    ans = int(over_digit())
    print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int,input().split())
d = list(map(int,input().split()))
ns = str(n)
e = []
for i in range(k):
    if i not in d:
        e.append(i)
f = True
ans_s = ''
for j in range(len(ns)):
    if f:
        for l in range(len(e)):
            if e[l] >= int(ns[j]):
                ans_s += str(e[l])
                if e[l] > int(ns[j]):
                    f_con = False
                break
    else:
        ans_s += str(e[0])
if ans_s != '':
    if int(ans_s)>=n:
        print(int(ans_s))
    else:
        ans = int(over_digit())
        print(ans)
else:
    ans = int(over_digit())
    print(ans)

def over_digit():
    ans_d = ''
    if e[0]==0:
        ans_d += str(e[1])
    else:
        ans_d += str(e[0])
    for m in range(len(ns)):
        ans_d += str(e[0])
    return ans_d

Submission status: Runtime Error

Solution code:
import bisect
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(0,10)) ^ set(D)
length = len(str(N))
comb = [int("".join(map(str, a))) for a in product(like_num, repeat=length)]
ind = bisect.bisect_left(comb, N)
print(comb[ind])

Submission status: Runtime Error

Solution code:
n, k = input().split()
d_list = list(map(int, input().split()))
u_list = [u for u in range(10) if u not in d_list]
replace_lis = [u_list[0]] * 10
for i in range(10):
    for j in range(i,10):
        if j in u_list:
            replace_lis[i] = j
            break

n_list = list(map(int, list(n)[::-1])) + [0]

for i in range(len(n_list)):
    if n_list[i] == 10:
        n_list[i] = 0
        n_list[i + 1] += 1
    if n_list[i] not in u_list:
        if n_list[i] > u_list[0]:
            n_list[i + 1] += 1
        n_list[i] = replace_lis[n_list[i]]

result = 0
for i in range(len(n_list)):
    result += n_list[i] * (10**i)

print(result)

Submission status: Runtime Error

Solution code:
n, k = input().split()
d_list = list(map(int, input().split()))
u_list = [u for u in range(10) if u not in d_list]
replace_lis = [u_list[0]] * 10
for i in range(10):
    for j in range(i,10):
        if j in u_list:
            replace_lis[i] = j
            break

n_list = list(map(int, list(n)[::-1])) + [0]

# print(f'n_list = {n_list}')
# print(f'u_list = {u_list}')
# print(f'replace_lis = {replace_lis}')
# print('result', end="")

for i in range(len(n_list)):
    if n_list[i] == 10:
        n_list[i] = 0
        n_list[i + 1] += 1
    if n_list[i] not in u_list:
        n_list[i] = replace_lis[n_list[i]]
        if n_list[i] == u_list[0]:
            n_list[i + 1] += 1

result = 0
for i in range(len(n_list)):
    result += n_list[i] * (10**i)


print(result)

Submission status: Runtime Error

Solution code:
n, k = input().split()
d_list = list(map(int, input().split()))
u_list = [u for u in range(10) if u not in d_list]
replace_lis = [u_list[0]] * 10
for i in range(10):
    for j in range(i,10):
        if j in u_list:
            replace_lis[i] = j
            break

n_list = list(map(int, list(n)[::-1])) + [0]

for i in range(len(n_list)):
    if n_list[i] not in u_list:
        n_list[i] = replace_lis[n_list[i]]
        if n_list[i] == u_list[0]:
            n_list[i + 1] += 1

result = 0
for i in range(len(n_list)):
    result += n_list[i] * (10**i)

print(result)

Submission status: Runtime Error

Solution code:
N, K = map(str, input().split(" "))

num_hate = list(map(int, input().split(" ")))
num_ok = [i for i in range(10) if i not in num_hate]

N_new = N

#print(num_ok)
for i in range(len(N)):
  if int(N[i]) in num_hate:
    if i == 0:
      if num_ok[i] == 0:
        N_new = N.replace(N[i], str(num_ok[i+1]), 1)
      else:
        N_new = N.replace(N[i], str(num_ok[i]), 1)
    else:
      N_new = N.replace(N[i], str(num_ok[i]), 1)
      
print(N_new)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int N, K;
int D[11];

int main() {
   cin >> N >> K;
   for (int i = 0; i < K; i++) {
      cin >> D[i];
   }

   ll num = N;
   while (1) {
      string s = to_string(num); // 数字を文字列にする

      bool ok = true; // 嫌いな数字が存在しないならtrue
      // 嫌いな数字の有無を判定
      for (int i = 0; i < K; i++) {
         if (count(s.begin(), s.end(), D[i]+'0')) {
            ok = false;
            num++;
            break;
         }
      }

      // 嫌いな数字が無ければnumを出力して終了
      if (ok) {
         cout << num << endl;
         return 0;
      }
   }

   return 0;
}

Submission status: Runtime Error

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

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in num_lis:
    for j in num_lis:
        for k in num_lis:
            for l in num_lis:
                a = 1000*i + 100 *j + 10*k + l
                if a>=N:
                    ans.append(a)
print(ans[0])

Submission status: Runtime Error

Solution code:
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in num_lis:
    for j in num_lis:
        for k in num_lis:
            for l in num_lis:
                a = 1000*i + 100 *j + 10*k + l
                if a>=N:
                    ans.append(a)
print(ans[0])

Submission status: Runtime Error

Solution code:
p,c=map(int,input().split())
dlike = list(map(int,input().split()))
like = [0,1,2,3,4,5,6,7,8,9]
num = list(str(p))
result = list()
for i in dlike:
    like.remove(i)

for j in range(len(num)):
    for k in like:
        if int(num[j]) <= k:
            result.append(str(k))
            break

print(int(''.join(result)))

Submission status: Runtime Error

Solution code:
import bisect
n, k = input().split()
A = sorted(list({i for i in range(10)} - set(map(int, input().split()))))
greater = False
ans = ""
for i in n:
  if greater:
    ans += str(A[0])
  else:
    t = A[bisect.bisect_left(A, int(i))]
    if t > int(i):
      greater = True
    ans += str(t)
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)

if len(nums) == 0:
  print(''.join([str(n) for n in N]))
  exit()

nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      j = j if j != -1 else 0
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Runtime Error

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)

if len(nums) == 0:
  print(N)
  exit()

nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      j = j if j != -1 else 0
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Runtime Error

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

if len(nums) == 0:
  print(N)
  exit()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect_left(nums,N[i])
      j = j if j != -1 else 0
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Runtime Error

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

if len(nums) == 0:
  print(N)
  exit()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect_left(nums,N[i])        
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Runtime Error

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

if len(nums) == 0:
  print(N)
  exit()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])        
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Runtime Error

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])        
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Runtime Error

Solution code:
# 1<=n<10000
n,k = map(int,input().split())
d = list(map(int,input().split()))

#使える数字を判別する。
nums = list(range(10))
s = [str(num) for num in nums if not num in d]
#print(s)

#使える数字の組み合わせでnより大きい最小値4ケタ
n = list(str(n))
ans = [0]*len(n)
for i in range(len(n)):
  if i == 0 and n[i] == "0" :
    # 0以外で一番小さい数を最初に持ってくる
    ans[0] = s[1:][0]
  else:
    # nよりも大きいやつを
    ans[i] = min([s_num for s_num in s if s_num >= n[i]])
    
print("".join(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

n,k = map(int, input().split())
d = list(map(int, input().split()))
num = [ i for i in range(10)]
num += d
a = [ x for x in set(num) if num.count(x)<2]
s = str(n)
m = len(s)
ans = []
for i in range(m):
    x = int(s[i])
    index = bisect.bisect_left(a,x)
    if a[index]==x:
        ans.append(str(x))
    else:
        ans.append(str(a[index]))
        for j in range(m-i-1):
            ans.append(str(a[0]))
        break
print("".join(ans))

Submission status: Runtime Error

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
#print("Keta is {}".format(Keta))
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])
#print("use is {}".format(use))
for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] <= use[j]:
            A.append(use[j])
    #print(i,A)
    Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)

Submission status: Runtime Error

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
#print("Keta is {}".format(Keta))
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])
#print("use is {}".format(use))
for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] <= use[j]:
            A.append(use[j])
    print(i,A)
    Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)

Submission status: Runtime Error

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
print("Keta is {}".format(Keta))
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])
print("use is {}".format(use))
for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] <= use[j]:
            A.append(use[j])
    Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=list(input().split())
x=list(range(1,10000)[::-1])
for i in d:
  a=[]
  for j in x:
    if i not in str(j):
      a.append(j)
  x=a
import bisect as bi
x=x[::-1]
print(x[bi.bisect_left(x,n)])

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=list(input().split())
x=list(range(1,10000)[::-1])
for i in d:
  a=[]
  for j in x:
    if i not in str(j):
      a.append(j)
  x=a
import bisect as bi
print(x[bi.bisect_left(x,n)])

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=list(input().split())
x=range(1,10000)[::-1]
for i in d:
  for j in x:
    if i in str(j):
      x.remove(j)
import bisect as bi
print(x[bi.bisect_left(x,n)])

Submission status: Runtime Error

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])

for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] == 0:
            Keta_Min.append(0)
        elif Keta[i] <= use[j]:
            A.append(use[j])
            Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)

Submission status: Runtime Error

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
print("Keta is {}".format(Keta))
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])
print("use is {}".format(use))
for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] == 0:
            Keta_Min.append(0)
        elif Keta[i] <= use[j]:
            A.append(use[j])
            Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)

Submission status: Runtime Error

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])
for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] <= use[j]:
            A.append(use[j])
            Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = set(map(int, input().split()))
safe = set(range(10)) - D

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if text(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y

answer = F(N)
print(answer)

Submission status: Runtime Error

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

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1

Submission status: Runtime Error

Solution code:
total, k = map(int, input().split())
ds = list(input().split())

for i in range(total,total*10+2):
  for d in ds:
    if d in list(str(ans)):
      break
  else:
    print(i)
    exit(0)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
D = list(set(D))
nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for d in D:
    nums.remove(d)
l = [int(x) for x in str(N)]
ans = []
for i, e in enumerate(l):
    if e in D:
        for num in nums:
            if e < num:
                ans.append(str(num))
        else:
            for _ in range(i + 1, len(l)):
                ans.append(str(min(nums)))
            break
    else:
        ans.append(str(e))
print(int(''.join(ans)))

Submission status: Runtime Error

Solution code:
line=input().split()

N=int(line[0])
K=int(line[1])

D=input().rstrip().split()


for i in range(N,10*N+1):
	s=str(i)
	flag=True
    for x in D:
		if x in s:
			flag=False
			break

	if flag:
		print(s)
		break
    
	else:
    	continue

Submission status: Runtime Error

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

ans = ''

for i in range(10):
    if not str(i) in d:
        sm = str(i)
        break

for i in range(len(str(n))):
    if n[i] in d:
        co = str(int(n[i])+1)
        while(1):
            if not co in d:
                break
            co = co + 1
        ans = ans + co + sm*(len(n)-i-1)
        break
    else:
        ans = ans + n[i]
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 入力
N, K = input().split()
K = int(K)
D = list(map(int, input().split()))

dd = [False]*10
for i in D:
  dd[i] = True

def find_min(lis, index):
  for i in range(index+1, len(lis)):
    if(lis[i] == False):
      return i

def make_num(num, order):
  ans = 0
  for i in range(order):
    ans += num*10**(order-1)
  return ans

n = len(N)
res = 0
for i in range(n):
  if(dd[int(N[i])] == True):
    res += find_min(dd, int(N[i])) * 10**(n-1-i)
    if(i<n-2):
      res += make_num(find_min(dd, -1), n-2)
      break;
  else:
    res += int(N[i])*10**(n-1-i)

print(res)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = sorted(list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(map(int, input().split()))))
n = str(n)
ans = ''
for i in n:
    for j in d:
        if j >= int(i):
            ans += str(j)
            break
print(int(ans))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
d = list(map(int, input().split()))
a = []
for i in range(10):
    if d.count(i) == 0:
        a.append(i)
ans = []
def dfs(s):
    if int(s) >= N or len(s) > len(str(N)):
        return s
    for i in a:
        S = dfs(s + str(i))
        if int(S) >= N:
            ans.append(int(S))
    return s
    
dfs('0')
print(min(ans))

Submission status: Runtime Error

Solution code:
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] # number
enableList = list(set(range(10)) - set(disabledList)) # number
resultList = [] # str, must reverse
isTenOver = False
for char in list(str(val)).reverse():
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if int(char) in enableList:
    isTenOver = False
    resultList.append(char)
    continue
  resultList = [min(enableList)] * len(resultList)
  if int(char) > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > int(char), enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(resultList.reverse()))

Submission status: Runtime Error

Solution code:
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] # number
enableList = list(set(range(10)) - set(disabledList)) # number
resultList = [] # int, must reverse
isTenOver = False
for char in list(str(val)).reverse():
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if int(char) in enableList:
    isTenOver = False
    resultList.append(char)
  elif int(char) > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > int(char), enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(resultList.reverse()))

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
D = input().split()
i = 0
money = N-1

while money < N:
  i = i+1
  ans = []
  ans += str(money+i)
  for j in range(len(ans)):
    for k in range(len(D)):
      if D[k] == ans[j]:
        flag = True
        break
    if flag:
      break
  if not(flag):
    money = money + i

print(money)

Submission status: Runtime Error

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

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

num = [i for i in range(1,10)]

dd = []

for i in d:
  num.remove(i)

total = 1000*min(num)
print(total)

Submission status: Runtime Error

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

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

num = [i for i in range(1,10)]

dd = []

for i in d:
  num.remove(i)

a = 0
for i in num:
  a += i*1000
print(a)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    ln = list(map(int, list(str(N))))
    c = 0
    
    for i in range(len(ln)-1,-1,-1):
        ln[i] += c
        while(ln[i] in D):
            ln[i] += 1
        c = ln[i] // 10
        ln[i] %= 10

    if(c > 0):
        l = [c] + l

    print(''.join(map(str, ln)))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    ln = list(map(int, list(str(N))))
    c = 0
    for i in range(len(ln)-1,-1,-1):
        ln[i] += c
        while(ln[i] in D):
            ln[i] += 1
        c = ln[i] // 10
        ln[i] %= 10

    if(c > 0):
        ln.appendleft(c)

    print(''.join(map(str, ln)))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()