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: Wrong Answer

Solution code:
"""
kari1 = '1000 8'
kari2 = '1 3 4 5 6 7 8 9'
kari1 = '9999 1'
kari2 = '0'
in1 = kari1.split()
in2 = kari2
"""
in1 = input().split()
in2 = input()

tukaeru = []
for num1 in range(10):
    if str(num1) not in in2:
        tukaeru.append(str(num1))
nedan = []
for num1 in range(len(in1[0])):
    nedan.append(in1[0][num1])

idx1 = 0
for item1 in nedan:
    if item1 not in tukaeru:
        break
    idx1 = idx1 + 1

if idx1 < len(nedan): #編集開始桁位置取得
    while idx1 >= 0:
        if tukaeru[-1] <= nedan[idx1]:
            idx1 = idx1 - 1
        else:
            break

    if idx1 == -1: #桁追加必要
        if tukaeru[0] == '0':
            nedan.insert(0, tukaeru[1])
        else:
            nedan.insert(0, tukaeru[0])
        idx1 = 1
    else: #桁追加不要
        for item1 in tukaeru:
            if item1 > nedan[idx1]:
                nedan[idx1] = item1
        idx1 = idx1 + 1
    for idx1 in range(idx1, len(nedan)):
        nedan[idx1] = tukaeru[0]

print(''.join(nedan))

Submission status: Wrong Answer

Solution code:
N, K, *D = open(0).read().split()
*N, = map(int, N)
*D, = map(int, D)
N = N[::-1]+[0]

for i in range(len(N)-1):
    while N[i] in D:
        N[i] += 1

    if N[i] > 9:
        N[i] %= 10
        N[i+1] += 1

if N[i] > 0:
    while N[i] in D:
        N[i] += 1
    i += 1

print(''.join([str(j) for j in N[:i][::-1]]))

Submission status: Wrong Answer

Solution code:
N, K, *D = open(0).read().split()
*N, = map(int, N)
*D, = map(int, D)
N += [0]

for i in range(len(N)-1):
    while N[i] in D:
        N[i] += 1

    if N[i] > 9:
        N[i] %= 10
        N[i+1] += 1

if N[i] > 0:
    while N[i] in D:
        N[i] += 1
    i += 1

print(''.join([str(j) for j in N[:i][::-1]]))

Submission status: Wrong Answer

Solution code:
n, k = input().split()
d = input().split()
valid = [i for i in range(10) if str(i) not in d]
ans = ''

if valid[-1] < int(n[0]):
    if valid[0] == 0:
        ans += str(valid[1])
    else:
        ans += str(valid[0])
    ans += str(valid[0]) * len(n)
else:
    for i, s in enumerate(n):
        if i > 0 and ans[0] > n[0]:
            ans += str(valid[0])
            continue

        for k in valid:
            if k >= int(s):
                ans += str(k)
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n,n2 = list(map(int,input().split()))
n3 = set(map(int,input().split()))

if  n3 ==0:
    print(n)
else:
    nlike ={1,2,3,4,5,6,7,8,9,} - n3
    nlike=[int(i) for i in nlike]
    print(nlike[0]*n)

Submission status: Wrong Answer

Solution code:
from sys import stdin

lines = stdin.readlines()
counter = []
each_line = []
for i, line in enumerate(lines):
    if i == 0:
        counter = [int(x) for x in (line.rstrip().split())]
    else:
        each_line = [str(x) for x in (line.rstrip().split())]

str_n = str(counter[0])
digit = len(str_n)

for num in range(counter[0], 10000, 1):
    num_str = str(num)
    for char in num_str:
        for dame in each_line:
            if char == dame:
                break
        else:
            continue
        break
    else:
        print(num)
        break

Submission status: Wrong Answer

Solution code:
n, K = map(int, input().split())
d = list(map(int, input().split()))

m = n
dis = 0
nums = []
while m > 0:
    dis += 1
    nums.insert(0, m % 10)
    m //= 10

ans = ""
for i in range(dis):
    if nums[i] not in d:
        ans += str(nums[i])
    else:
        a = nums[i]
        while a in d:
            a += 1
        ans += str(a)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys

N, _ = map(int, input().split())
D = input().split()

answer = sys.maxsize
for x in range(N, 10000):
    s = str(x)
    if all([y not in s for y in D]):
        answer = min(answer, x)
print(answer)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = set(map(int, input().split()))
x={i for i in range(10)}
y=x-D
z=''
for i in range(len(N)):
    for j in y:
        if j > int(N[i]):
            z=z+str(j)
            print(z+str(min(list(y)))*(len(N)-1-i))
            exit()
        elif j == int(N[i]):
            z=z+str(j)
            if i==len(N)-1 :
                print(z)
                exit()
            break
    if j < int(N[i]):
        break
print(str(min(y-{0}))+str(min(y))*len(N))

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = set(map(int, input().split()))
x={i for i in range(10)}
y=x-D
z=''
for i in range(len(N)):
    for j in y:
        if j > int(N[i]):
            z=z+str(j)
            print(z+str(min(list(y)))*(len(N)-1-i))
            exit()
        elif j == int(N[i]):
            z=z+str(j)
            print(z)
            break
print(str(min(y-{0}))+str(min(y))*len(N))

Submission status: Wrong Answer

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


def unique(string, array):
    for a1 in array:
        if a1 in string:
            return False
    return True


amount = 0
total = 0
while True:
    amount += 1
    total = amount * N
    if unique(str(total), D):
        print(total)
        exit()

Submission status: Wrong Answer

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


def unique(arry1, arry2):
    for a1 in arry1:
        if a1 in arry2:
            return False
    return True


amount = 0
total = 0
while True:
    amount += 1
    total = amount * N
    token = list(map(int, str(total)))
    if unique(token, D):
        print(total)
        exit()

Submission status: Wrong Answer

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


def unique(arry1, arry2):
    for a1 in arry1:
        if a1 in arry2:
            return False
    return True


amount = 0
total = 0
while True:
    amount += 1
    total = amount * N
    token = list(map(int, str(total)))
    if unique(D, token):
        break

print(total)

Submission status: Wrong Answer

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

n, k = MAP()
d = LIST()
ns = [int(i) for i in str(n)]
ns.insert(0, 0)
l = len(ns)
i = 1
flag = False
while i < l:
    nsp = ns[i]
    flag2 = False
    while ns[i] in d:
        if flag and ns[i] > 0:
            ns[i] -= 1
        else:
            ns[i] += 1
        if ns[i] == 10:
            ns[i] = 0
            ns[i - 1] += 1
            flag2 = True
    if nsp < ns[i]:
        flag = True
    if flag2:
        i -= 1
    else:
        i += 1
ans = ''
for i in range(l):
    ans += str(ns[i])
ans = int(ans)
print(ans)

Submission status: Wrong Answer

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

n, k = MAP()
d = LIST()
ns = [int(i) for i in str(n)]
ns.insert(0, 0)
l = len(ns)
i = 1
flag = False
while i < l:
    while ns[i] in d:
        if flag and ns[i] > 0:
            ns[i] -= 1
        else:
            ns[i] += 1
            flag = True
        if ns[i] == 10:
            ns[i] = 0
            ns[i - 1] += 1
            i -= 2
    i += 1
ans = ''
for i in range(l):
    ans += str(ns[i])
ans = int(ans)
print(ans)

Submission status: Wrong Answer

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

n, k = MAP()
d = LIST()
flag = True
ns = [int(i) for i in str(n)]
ns.insert(0, 0)
l = len(ns)
for i in reversed(range(1, l)):
    while ns[i] in d:
        ns[i] += 1
        if ns[i] == 10:
            ns[i] = 0
            ns[i - 1] += 1
ans = ''
for i in range(l):
    ans += str(ns[i])
ans = int(ans)
print(ans)

Submission status: Wrong Answer

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

for i in range(n, 10001):
  ok = True
  for s in str(i):
    if s in ds:
      ok = False
      break
  if ok:
    print(i)
    break

Submission status: Wrong Answer

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

for i in range(n, 10001):
  ok = True
  for s in str(i):
    if s in ds:
      ok = False
      break
  if ok:
    print(i)
    break

Submission status: Wrong Answer

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

for i in range(n, 10000):
  ok = True
  for s in str(i):
    if s in ds:
      ok = False
  if ok:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(input())
restrict = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i):
	global restrict
	if not restrict:
		return min_number
	for s in range(10):
		if (str(s) not in d_ng_list) and str(s) >= n_price[i]:
			if s > int(n_price[i]):
				restrict = False
			return str(s)
		#if not found
		restrict = False
		return str(min_number+min_number)

def rec_cal_pay(answer, i, restrict):
	if i == n_length-1:
		answer += find_number(i)
		print(answer)
		return
	else:
		c = find_number(i)
		rec_cal_pay(answer+c, i+1, restrict)

rec_cal_pay(answer, 0, restrict)

Submission status: Wrong Answer

Solution code:
miis=lambda:map(int,input().split())
lmiis=lambda:list(map(int,input().split()))

n,k=miis()
n_l=[int(i) for i in reversed(str(n))]

d=lmiis()

ans=[]

i=0
th=len(n_l)
while i<th:
  while True:
    if n_l[i] not in d:
      ans.append(n_l[i])
      i+=1
      break
    else:
      if n_l[i]<=8:
        n_l[i]+=1
      else:
        n+=10**i
        n_l=[int(i) for i in reversed(str(n))]
        th=len(n_l)

ans=reversed(ans)
ans=[str(i) for i in ans]
print(''.join(ans))

Submission status: Wrong Answer

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

for i in range(n,10001):
    x = 0
    for j in str(i):
       
        if int(j) in d:
            x = 1
            break
   
    if x == 1:
        pass
    else:
        break
print(i)

Submission status: Wrong Answer

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

while True:
    ans = N * count
    if len(set(D) & set(list(str(ans)))) == 0:
        break
    count += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def check(n,s):
    n=str(n)
    for i in range(len(n)):
        if int(n[i]) not in s:
            return False
    else:
        return True

def main():
    #入力
    readline=stdin.readline
    N,K=map(int,readline().split())
    D=list(map(int,readline().split()))

    s=set([0,1,2,3,4,5,6,7,8,9])
    s0=set(D)
    s1=s-s0
    M=int(str(max(s1))*len(str(N)))

    for i in range(N,M+1):
        if check(i,s1):
            print(i)
            break

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
yen, num = list(map(int, input().split()))
dislike = list(map(int, input().split()))
dislike.sort()
a = [1]*10
ans = []
yenstr = list(str(yen))
for i in range(num):
  a[dislike[i]] = 0
for i in range(10):
  if a[i] != 0:
    ans.append(i)
    
if ans[len(ans)-1]<int(yenstr[0]):
  if ans[0] == 0:
    yenstr.insert(0, ans[1])
  else:
    yenstr.insert(0, ans[0])
  
    
for i in range(len(yenstr)):
    for j in range(len(ans)):
      if int(yenstr[i]) <= ans[j]:
        print(ans[j], end='')
        break
      elif j == len(ans)-1:
        print(ans[0], end='')
print()

Submission status: Wrong Answer

Solution code:
yen, num = list(map(int, input().split()))
dislike = list(map(int, input().split()))
dislike.sort()
a = [1]*10
ans = []
yenstr = list(str(yen))
for i in range(num):
  a[dislike[i]] = 0
for i in range(10):
  if a[i] != 0:
    ans.append(i)
for i in range(len(yenstr)):
    for j in range(len(ans)):
      if int(yenstr[i]) <= ans[j]:
        print(ans[j], end='')
        break
print()

Submission status: Wrong Answer

Solution code:
yen, num = list(map(int, input().split()))
dislike = list(map(int, input().split()))
dislike.sort()
a = [1]*10
yenstr = list(str(yen))
for i in range(num):
  a[dislike[i]] = 0
#print(a)  
for i in range(yen, 10001):
  x = list(str(i))

  for j in range(len(x)):
    if a[int(x[j])] == 0:
      #print(j, 'break')
      break
  if j == len(x)-1:
    print(i)
    exit()

Submission status: Wrong Answer

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

ans = 0
for i in range(n, 20001):
    if set(list(str(i))) & d == set():
        ans = i
        break

print(ans)

Submission status: Wrong Answer

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

l = set(map(str, range(10))) - d

ans = 0
for i in range(n, 10001):
    if set(list(str(i))) & d == set():
        ans = i
        break

print(ans)

Submission status: Wrong Answer

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

l = set(map(str, range(10))) - d

for i in range(n, 10001):
    if set(list(str(i))) & d == set():
        print(i)
        break

Submission status: Wrong Answer

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

n = list(map(int, list(n)))
ans = ""
for i in range(len(n)):
    f = 1
    if n[i] in d:
        for j in range(10 - n[i]):
            if n[i] + j not in d:
                ans += str(n[i] + j)
                f = 0
                break
        if f:
            if i == 0:
                for l in range(1, 10):
                    if l not in d:
                        ans += str(l) + str(0)
                        break
            else:
                for l in range(10):
                    if l not in d:
                        ans += str(l)
                        break
    else:
        ans += str(n[i])

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,(input().split()))
li=[]
m=set(input())
for j in range(N,10000):
    if len(set(m & set(str(j))))==0:
        print(j)
        break

Submission status: Wrong Answer

Solution code:
N,K=map(int,(input().split()))
li=[]
m=set(input())
for j in range(N,10000):
    if m & set(str(j)) == False:
        print(j)
        break

Submission status: Wrong Answer

Solution code:
N,K=map(int,(input().split()))
li=list(map(int,input().split()))
for j in range(N,10000):
    k=0
    for t in str(j):
        if int(t) in li:
            k=1
            break
    else:
        if k==0:
            print(j)
            break

Submission status: Wrong Answer

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

nums = [i for i in range(10)]
for d in D:
    nums.remove(d)
digit = len(str(N))
ret = []
INF = 10**5


def dfs(cur, value):
    if cur == digit:
        if int(value) >= N:
            return value
        else:
            return INF
    for i in nums:
        if cur == 0 and i == 0:
            continue
        ret.append(dfs(cur+1, value + str(i)))
    return min(list(map(int, ret)))


print(dfs(0, ''))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s, k = input().split()
  n = len(s)
  ds = list(map(int, input().split()))
  ans = 0
  flag = False
  for i, c in enumerate(list(s)[::-1]):
    c = int(c)
    if flag:
      c += 1
    while c in ds:
      c += 1
    if c == 10:
      flag = True
    else:
      flag = False
    ans += c * (10 ** i)
  print(ans)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dis = [_ for _ in input().split()]
for yen in range(1, 10001):
    if yen < n:
        pass
    else:
        if len(set(list(str(yen))) & set(dis)) == 0:
            print(yen)
            exit()

Submission status: Wrong Answer

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

i = 1
while i < 10000:
    if i >= N:
        j = str(i)
        j = list(map(int, j))
        if all(a not in D for a in j):
            print(i)
            exit()
        else:
            i += 1
            continue
    else:
        i += 1

Submission status: Wrong Answer

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

for i in D:
    L.remove(i)

N = str(N)
N = list(map(int, N))

A = []
for i in range(len(N)):
    for j in range(len(L)):
        if i == 0:
            if N[i] <= L[j]:
                A.append(L[j])
                break
        else:
            A.append(min(L))
            break

A = ''.join(map(str, A))
print(A)

Submission status: Wrong Answer

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

for i in D:
    L.remove(i)

#print(L)

N = str(N)
N = list(map(int, N))

#print(N)

A = []
for i in range(len(N)):
#    print(N[i])
    for j in range(len(L)):
#        print(L[j])
        if N[i] <= L[j]:
            A.append(L[j])
#            print(A)
            break

A = ''.join(map(str, A))
print(A)

Submission status: Wrong Answer

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

for i in D:
    L.remove(i)

print(L)

N = str(N)
N = list(map(int, N))

print(N)

A = []
for i in range(len(N)):
    print(N[i])
    for j in range(len(L)):
        print(L[j])
        if N[i] <= L[j]:
            A.append(L[j])
            print(A)
            break

A = ''.join(map(str, A))
print(A)

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n, k = input().split()
    d = list(map(int,input().split()))
    use = []
    for i in range(0,10):
        if i in d:
            continue
        else:
            use.append(i)
    ans = []
    flag = True
    for j in range(len(n)):

        if flag:
            for i in use:
                if int(n[j]) < i:
                    ans.append(str(i))
                    flag = False
                    break
                elif int(n[j]) == i:
                    ans.append(str(i))
                    break
        else:
            ans.append(str(use[0]))
    #print(ans)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n, k = input().split()
    d = list(map(int,input().split()))
    use = []
    for i in range(0,10):
        if i in d:
            continue
        else:
            use.append(i)
    ans = []
    flag = True
    for j in range(len(n)):
        if flag:
            for i in use:
                if int(n[j]) < i:
                    ans.append(str(i))
                    flag = False
                    break
                elif int(n[j]) == i:
                    ans.append(str(i))
                    break
    #print(ans)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n, k = input().split()
    d = list(map(int,input().split()))
    use = []
    for i in range(0,10):
        if i in d:
            continue
        else:
            use.append(i)
    ans = []
    flag = True
    for j in range(len(n)):
        if flag:
            for i in use:
                if int(n[j]) < i:
                    ans.append(str(i))
                    flag = False
                    break
                elif int(n[j]) == i:
                    ans.append(str(i))
    #print(ans)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n, k = input().split()
    d = list(map(int,input().split()))
    use = []
    for i in range(0,10):
        if i in d:
            continue
        else:
            use.append(i)
    ans = []
    for j in range(len(n)):
        for i in use:
            if int(n[j]) <= i:
                ans.append(str(i))
                break

    #print(ans)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in D:
    A.remove(i)

j = str(N)#iを文字列に
L = list(map(int, j))#iの各行を数字としてリストに

B = []
for i in range(len(L)):
    for j in range(len(A)):
        if L[i] <= A[j]:
            B.append(A[j])
            break

B = ''.join(map(str, B))
print(B)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s,p = map(int,input().split())
n = str(s)
a = list(map(int,input().split()))
mi = -1
mi_non_zero = 0
for i in range(10):
    if i not in a:
        if mi == -1:
            mi = i
            if i != 0: 
                mi_non_zero = mi
                break
        else: 
            mi_non_zero = i
            break
#print(mi,mi_non_zero)
ans = 0
for i in range(len(n)-1,-1,-1):#１のくらいからみていく
    bit = 0 #くりあがり
    k = int(n[i])
    #print(k)
    for j in range(k+bit,10):# k以上の値で使えるものがあればOK
        if j in a:
            if j == 9:
                bit = 1
                ans += mi *(10**(len(n)-1-i))
                break
        else: 
            ans += (j+bit)*(10**(len(n)-1-i))
            break
    if i == 0 and bit == 1:
        ans += mi_non_zero*(10**(len(n)-1-i))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(str, input().split()))
ans = n - 1
for i in range(0,10001):
    ok = True
    ans += 1
    for j in range(len(str(ans))):
        if str(ans)[j] in d:
            ok = False
            break
    if ok:
        print (ans)
        exit ()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(int, input().split()))
ans = n - 1
for i in range(n,10001):
    ng=False
    ans += 1
    for j in range(len(str(ans))):
        if int(str(ans)[j]) in d:
            ng=True
            break
    if not ng:
        print (ans)
        exit ()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(int, input().split()))
ans = n -1
for i in range(n,10000):
    ng=False
    ans += 1
    for j in range(len(str(ans))):
        if int(str(ans)[j]) in d:
            ng=True
            break
    if not ng:
        print (ans)
        exit ()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().strip().split())
d = list(input().split())
for x in range(n,100000):
    for y in d:
        if y in str(x):
            break
        else:
            print(x)
            break