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 =map(int, input().split())
#d = list(map(int, input().split()))
d = list(input().split())
#print(d)

def check(kakaku, negative_number):
  check_sum = 1
  for i in negative_number:
    if i in str(kakaku):
      #print(i)
      check_sum = 0
      break
    else:
      pass
  return check_sum

while check(n, d) == 0:
  n += 1

print(n)

Submission status: Accepted

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

usable = set(range(10)) - set(d)

while True:
    if {int(i) for i in set(list(str(n)))} <= usable:
        print(n)
        exit()
    else:
        n += 1

Submission status: Accepted

Solution code:
a,b = map(int,input().split()) 
li1 = set(map(int,input().split()))
li2 = {1,2,3,4,5,6,7,8,9,0}
nu = list(li1^li2)

i = 1
while True:
    aa = list(str(a))
    aa = [int(x) for x in aa]
    if set(aa).issubset(set(nu)):
        print(a)
        break
    a += i

Submission status: Accepted

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

num = N
flag = True

while flag:
    for i in D:
        if str(i) in str(num):
            num += 1
            break
    else:
        print(num)
        flag = False

Submission status: Accepted

Solution code:
import sys

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

D_ava = list(map(str,[i for i in range(1,10) if i not in D]))
for s in range(N, 10**5+1):
	ss = list(set(str(s)))
	cond = True
	for sss in ss:
		if sss in D:
			cond = False
			break
	if cond == True:
		print(s)
		sys.exit()
	else:
		continue

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
ans=n
while 1:
  hoge=list(str(ans))
  flag=0
  for i in range(len(l)):
    flag+=hoge.count(str(l[i]))
  if(flag==0):
    print(ans)
    exit()
  ans+=1

Submission status: Accepted

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

d = [i for i in range(10)]
din = list(map(int,input().split()))

for i in din:
    d.remove(i)

flg = 0

for i in range(n,100000):
    for j in range(len(din)):
        #嫌いな数値が居た場合
        if str(din[j]) in str(i):
            flg=1
            break
    if flg == 0:
        print(i)
        break
    else:
        flg=0

Submission status: Accepted

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

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

Submission status: Accepted

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

d = input().split()

while True:
  not_in = True
  for i in range(k):
    if d[i] in str(n):
      not_in = False
      break
  if not_in:
    print(n)
    break
  n += 1

Submission status: Accepted

Solution code:
import sys

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

for i in range(N, 10 ** 7):
    ansb = True
    for j in d:
        if str(i).count(str(j)) != 0:
            ansb = False
            break
    if ansb:
        print(i)
        sys.exit()

Submission status: Accepted

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

isNotMin = True

temp = N * 1

while isNotMin:
    for i in str(temp):
        if int(i) in D:
            temp += 1
            isNotMin = True
            break
        else:
            isNotMin = False

print(temp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))
array = list(map(int,input().split()))
# N=1000
# K=8
# array = [1,3,4,5,6,7,8,9]

# Farray = [0,1,2,3,4,5,6,7,8,9]
# array = set(Farray)-set(array)
# array = list(map(int,array))
i=0
result=[]

#桁上がり未考慮だった。
# while i<len(str(N)):
#     j=0
#     for j in range(len(array)):
#         if int(str(N)[i]) <= array[j]:
#             result.append(array[j])
#             break
#     i+=1
flag=False
while flag == False :
    # print(N)
    for i in range(len(str(N))):
        if int(str(N)[i]) in array:
            break
    else:
        flag=True

    N+=1

print(N-1)

Submission status: Accepted

Solution code:
def f(S):
  SS = str(S)
  for d in D:
    if d in SS:
      return True
  return False

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

while f(N):
  N += 1

print(N)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools,pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
D = LI()
nums = [str(i) for i in range(0, 10) if i not in D]

"""
使える数字の中で一番低いものから試していく
見つかったら各桁試していく

"""

all_nums = []
for i in range(N, 99999):
    # 全数字の列挙
    all_nums.append(i)
for num in all_nums:
    if num >= N:
        if all(i in nums for i in str(num)):
            print(num)
            exit()

Submission status: Accepted

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

while not set(N).isdisjoint(D):
    N=str(int(N)+1)
else:
    print(N)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dislike = [str(i) for i in input().split()]
strn = str(n)

while(1):
  flag = 1
  for i in range(len(strn)):
    if strn[i] in dislike:
      flag = 0
  if flag == 1:
    print(n)
    break
  else:
    n += 1
    strn = str(n)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]


def dfs(n):
    if n != '':
        if n[0] == '0':
            return 10 ** 7
        elif int(n) >= N:
            return int(n)
    output = 10 ** 7
    for l in L:
        output = min(output, dfs(n + str(l)))
    return output


print(dfs(''))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=set(input().split())
while 1:
    l=str(N)
    for i in range(len(l)):
        if l[i] in D:
            break
    else:
        print(N)
        break
    N+=1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=[i for i in input().split()]
while True:
    s=str(n)
    s=list(s)
    check=0
    for i in s:
        if i in d:
            break
        check+=1
        if check==len(s):
            print(''.join(s))
            exit()
    n+=1

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    global ans
    if n != '' and n[0] == '0':
        return
    if n != '' and int(n) >= ans:
        return
    if len(n) >= len(str(N)):
        if int(n) >= N:
            ans = int(n)
    for l in L:
        dfs(n + str(l))


dfs('')
print(ans)

Submission status: Accepted

Solution code:
a, n = map(int, input().split())
b = list(map(str, input().split()))
c = str(a)
while True:
    check = True
    for i in range(len(c)):
        if c[i] in b:
            c = str(int(c) + 1)
            check = False
            break
    if check:
        print(c)
        break

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    a=input()
    for i in range(n,100000):
        bl = 1
        for j in str(i):
            if j in a:
                bl=0
                continue
        if bl:
            return i
print(main())

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ng = set(list(input().split()))
while True:
    if len(set(str(n))&ng)==0:
        break
    else:
        n+=1
print(n)

Submission status: Accepted

Solution code:
n, k = input().split()
d = set(input().split())
while not set(n).isdisjoint(d):
    n = str(int(n) + 1)
else:
    print(n)

Submission status: Accepted

Solution code:
n, k = input().split()
d = set(input().split())
while True:
    if set(n).isdisjoint(d):
        print(n)
        break
    else:
        n = str(int(n) + 1)

Submission status: Accepted

Solution code:
def main():
    n, k = (int(i) for i in input().split())
    d = {i for i in input().split()}
    while set(str(n)) & d:
        n += 1
    print(n)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, k = na()
ddd = input().split()
for i in range(n, 100000):
    flag = True
    for c in str(i):
        if c in ddd:
            flag = False
            break
    if flag:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
import itertools

N, K = map(int,input().split())
D = list(map(int,input().split()))
N = str(N)
d = []
d_min = 10
for i in range(10):
    if i in D:
        continue
    else:
        if i != 0:
            d_min = min(d_min, i)
        d.append(str(i))
if '0' in d:
    ans = str(d_min) + '0' * len(N)
else:
    ans = str(d_min) * (len(N) + 1)
ans = int(ans)
for s in itertools.product(d, repeat=len(N)):
    s = ''.join(s)
    s = int(s)
    if s >= int(N):
        ans = min(ans, s)
print(ans)

Submission status: Accepted

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

for i in range(n,10**6):
  flag = 0 # Listに入っていたら1にする
  for j in str(i):
    if int(j) in List: # intかstrに型を揃える
      flag = 1
      break
      
  if flag == 0:
    print(i)
    exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Dlist = list(map(int, input().split()))
    
alist = list(set([0,1,2,3,4,5,6,7,8,9]) - set(Dlist))
if sum(x==0 for x in alist) == 0:
    b = min(alist)
else:
    b = min(list(set(alist)-set([0])))
strN = str(N)
c = ""
ans = ""
flag = True
for i in range(len(strN)):
    iN = int(strN[i])
    if sum(x>=iN for x in alist) == 0:
        ans = str(b) + str(min(alist))*len(strN)
        flag = False
        break
    elif sum(x==iN for x in alist) == 0:
        ans = c + str(min([a for a in alist if a>iN])) + str(min(alist))*(len(strN)-1-i)
        flag = False
        break
    else:
        c = c + str(iN)

if flag:
    print(N)
else:
    print(int(ans))

Submission status: Accepted

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

while True:
  ns = str(n)
  exists_dislike_number = False
  for ds in d:
    if ns.count(str(ds)) > 0:
      exists_dislike_number = True
  
  if exists_dislike_number:
    n += 1
  else:
    break

print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_correct(disabled, val):
  for c in str(val):
    if c in disabled:
      return False
  return True

def main():
  n, k = [int(x) for x in raw_input().split(' ')]
  disabled = [x for x in raw_input().split(' ')]
  while not is_correct(disabled, n):
    n += 1
  print(n)

main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
while 1<2:
  nn=list(map(int,list(str(n))))
  if len(set(nn+d))<len(set(nn))+len(set(d)):
    n+=1
  else:
    print(n)
    break

Submission status: Accepted

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
while True:
    flag=0
    for money_element in list(str(money)):
        if money_element in no_list:
            flag=1
            money+=1
            break
    if flag==0:
        print(money)
        break

Submission status: Accepted

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
for i in range(money,100000):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=[int(i) for i in input().split()]
d=set(d)
i=0
while True:
    s=str(n)
    c=0
    for i in s:
        if int(i) in d:
            break
        else:
            c+=1
    if c==len(s):
        print(n)
        exit()
    n+=1

Submission status: Accepted

Solution code:
import itertools

N,K= map(int,input().split())
D = set(input().split())
while len(set(str(N))&D) != 0:
    N = N + 1
print(N)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
a = n
f = False
while f == False:
    li = []
    for i in str(a):
        li.append(int(i))
    if set(li) & set(d) == set():
        print(a)
        f = True
    else:
        a += 1

Submission status: Accepted

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

M = N
while True:
  N_ = 0
  for i,n in enumerate(N):
    if n in D:
      N_ += (int(n) + 1) * 10 ** (len(N) - 1 - i)
      break
    else:
      N_ += int(n) * 10 ** (len(N) - 1 - i)
  else:
    break
  N = str(N_)
          
print(N)

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
dislike_numbers = input().split()

for i in range(n, 99999):
    if all(dn not in str(i) for dn in dislike_numbers):
        print(i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    D = inputList()
    
    base = list(range(10))
    for vol in D:
        base.remove(vol)
        
    ans = ""
    NN = str(N)
    flg = False
    for i,val in enumerate(NN):
        isInp = False
        for j,vol in enumerate(base):
            if flg == True:
                ans += str(vol)
                isInp = True
                break
            tmp = int(val)
            if tmp == vol:
                ans += val
                isInp = True
                break
            elif tmp < vol:
                flg = True
                ans += str(vol)
                isInp = True
                break
            else:
                continue
        
        if isInp == False:
            ans += "*"
    
    if "*" not in ans:
        print(ans)
        sys.exit()
    
    ans = list(ans)
    ans_T = ""
    if ans[0] == "*" or 1 == 1:
        if base[0] != 0:
            ans_T += str(base[0])
        else:
            ans_T += str(base[1])
        for i in range(len(str(N))):
            ans_T += str(base[0])
        print(ans_T)
        sys.exit()
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    D = inputList()
    
    base = list(range(10))
    for vol in D:
        base.remove(vol)
        
    ans = ""
    NN = str(N)
    flg = False
    for i,val in enumerate(NN):
        isInp = False
        for j,vol in enumerate(base):
            if flg == True:
                ans += str(vol)
                isInp = True
                break
            tmp = int(val)
            if tmp == vol:
                ans += val
                isInp = True
                break
            elif tmp < vol:
                flg = True
                ans += str(vol)
                isInp = True
                break
            else:
                continue
        
        if isInp == False:
            ans += "*"
    
    if "*" not in ans:
        print(ans)
        sys.exit()
    
    ans = list(ans)
    ans_T = ""
    if ans[0] == "*" or 1 == 1:
        if base[0] != 0:
            ans_T += str(base[0])
        else:
            ans_T += str(base[1])
        for i in range(len(str(N))):
            ans_T += str(base[0])
        print(ans_T)
        sys.exit()
        
    '''
    mem = []
    for i in ans:
        if i == str(base[-1]):
            mem.append(1)
        elif i == "*":
            mem.append(2)
        else:
            mem.append(0)
    
    ttt = ""
    tmp = ""
    flg = False
    for i, val in enumerate(ans):
        if mem[i] == 2:
            ttt += str(base[0])
            flg = True
        else:
            ttt += "-"
        if flg == False:
            tmp = val
            
    print("".join(ans))
    '''
    
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Ds = set(input().split())

n = N

while set(str(n)) & Ds:
    n += 1

print(n)

Submission status: Accepted

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

nums = []
for x in range(10):
    if x in ds:
        nums.append(1)
    else:
        nums.append(0)

res = 0
for x in range(n, n*10):
    ys = list(map(int,list(str(x))))
    flag = False
    for y in ys:
        if nums[y]:
            flag = True
            break
    if flag:
        continue
    else:
        res = x
        break
print(res)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(str, input().split()))
num = [0 for _ in range(10)]

for v in d:
    num[int(v)] = 1

for j in range(10 * n):
    v = n + j
    v_l = list(str(v))
    flag = True
    for i in v_l:
        if num[int(i)] == 1:
            flag = False
            break
    if flag:
        print(v)
        exit()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc042/tasks/arc058_a
# C - こだわり者いろはちゃん / Iroha's Obsession
import copy

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

# 一番上の桁から見ていく
use_list = list(set(range(10)) - set(d_list))
n_list = [int(x) for x in list(str(N))]

# 各桁ごとに、使える数字を使っているかどうか洗い出す
keta_list = [x in use_list for x in n_list]

def can_update(old_n):
    kouho_n_list = [x for x in use_list if x > old_n]
    if kouho_n_list:
        return True
    else:
        return False

# 一番左に出てくるFalseの桁
k_index = keta_list.index(False) if False in keta_list else -1

if k_index != -1:
    is_ok = False

    for index in range(k_index, -1, -1):
        # 途中桁の場合
        old_n = n_list[index]
        # その桁で使用可能な数字があるか
        if can_update(old_n):
            # その桁で使用可能な数字がある
            kouho_n_list = [x for x in use_list if x > old_n]
            new_n = min(kouho_n_list)
            new_n_list = n_list[:index] + [new_n]
            # 当該桁以降は、使用可能な最小値で構成する
            if index < len(keta_list):
                new_n_list += [min(use_list)] * (len(keta_list) - (index+1))
            ans = int(''.join([str(x) for x in new_n_list]))
            is_ok = True
            break

        if not is_ok:
            # 最大桁を更新する
            new_n = sorted(use_list)[1] if min(use_list) == 0 else min(use_list)
            # 残りの桁を全て、使用可能な最小値で置き換える
            new_n = str(new_n) + str(min(use_list)) * len(keta_list)
            ans = int(new_n)

else:
    # 使える数字だけで構成されているので、そのままでOK
    ans = N

print(ans)

Submission status: Accepted

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

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

    l = len(str(N))
    cand = [""]
    for _ in range(l):
        temp = []
        for s in cand:
            for f in F:
                temp.append(s+str(f))
        cand = temp

    lv = [int(s) for s in cand]
    for s in sorted(lv):
        if int(s) >= N: return int(s)

    minf = 9
    for f in F:
        if f > 0: minf = min(minf, f)

    cand = sorted(cand)
    return int(str(minf) + cand[0])

if __name__ == '__main__':

    print(main())

Submission status: Accepted

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

flag=False
while True:
  yen=str(n)
  for i in range(len(yen)):
    if int(yen[i]) in d:
      n+=1
      flag=True
      break
  if flag:
    flag = False
    continue
  break
print(n)

Submission status: Accepted

Solution code:
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



def main():
    n, k = LI()
    n_list = LI()
    i = n
    while True:
        flag = 0
        for j in n_list:
            if str(j) in str(i):
                flag = 1
        if flag == 0:
            break
        i += 1
    return i





print(main())

Submission status: Accepted

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

dislike_number = set(map(int, input().split()))
num = set([i for i in range(10)])
ok_num = list(num - dislike_number)
ok_num = sorted(ok_num)



max_len = len(str(N))
widths=[str(max(ok_num))]*(max_len+1)
min_value=10**(max_len+1)

for i in range(0,max_len+1):
    if i==0:
        temp=int("".join(widths[1:]))
        if N <= temp < min_value:
            min_value=temp
            widths[0]="0"
            continue
    for num in ok_num:
        widths[i]=str(num)
        temp=int("".join(widths))
        if N <= temp < min_value:
            min_value=temp
            break
print(min_value)

Submission status: Accepted

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

while(True):
    n = str(N)
    flag = True
    for i in range(len(n)):
        if(int(n[i]) in d):
            flag = False
            break
    if(flag):
        break
    else:
        N += 1
print(N)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
set_d = set(map(int, input().split()))
g = n
while(True):
    set_g = set(str(g))
    set_g = [int(i) for i in set_g]
    for i in set_g:
        if i in set_d:
            g += 1
            break
    else:
        break
print(g)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, k = map(int, input().split())
    dl = set(map(int, input().split()))

    for i in range(n, 100000):
        if i < n:
            continue
        candi = list(map(int, list(str(i))))
        available = True
        for c in candi:
            if c in dl:
                available = False
                break
        if available:
            print(i)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

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

# 使える数字は？
nums = []
for c in list('0123456789'):
    if c in D:
        pass
    else:
        nums.append(c)

#print(nums)

ret = []
def dfs(next_value, nums, ans):
    ans += next_value

    if int(ans) >= N:
        ret.append(ans)
        return

    for c in nums:
        # 0 が結合し続けると無限ループになるはず
        if ans == '0' and c == '0':
            pass
        else:
            dfs(c, nums, ans)

    return ans

dfs('0', nums, '')

A = list(map(int, ret))
print(min(A))

Submission status: Accepted

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

for i in range(n,100000):
    ans=list(str(i))
    flag=0
    for x in ans:
        if x  in d:
            flag=1
    if flag==0:
        print(''.join(ans))
        sys.exit()

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    d = list(input().split())
    i = n
    while True:
        stri = list(str(i))
        flg = True
        for j in d:
            if j in stri:
                flg = False
        if flg:
            print(i)
            return
        i += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, _ = [int(x) for x in input().split()]
dn = set(input().split())

i = n
answer = n
while len(set(str(n)) & dn) > 0:
    n += 1
print(n)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
 
#print(l)
while True:    
    N_str = str(N)
    frag = 0
    for i in range(len(N_str)):
        if int(N_str[i]) in l:
            #print("yes")
            frag = 1
            break
    if frag == 0:
        break
    else:
        N += 1
print(N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]

#print(l)
while True:    
    N_str = str(N)
    frag = 0
    for i in range(len(N_str)):
        if int(N_str[i]) in l:
            #print("yes")
            frag = 1
            break
    if frag == 0:
        break
    else:
        N += 1
print(N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=set(map(str,input().split()))
i=n
a=[]
for j in range(len(str(n))):
	a.append(str(n)[j])
a=set(a)
while i<10**5+1:
	if len(a&d)==0:
		print(i)
		exit()
	else:
		i+=1
		a=[]
		for j in range(len(str(i))):
			a.append(str(i)[j])
		a=set(a)

Submission status: Accepted

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

while True:
  s=str(n)
  if not any(tmp in s for tmp in str(d)):
    break
  n+=1
print(n)

Submission status: Accepted

Solution code:
inputted = input().split(" ")
N=int(inputted[0])
K=int(inputted[1])
s = [i for i in input() if i != ' ']

num=0
while True:
  num+=1
  match=[i for i in str(num) if i in s]
  if num>=N and len(match)==0:
    print(num)
    break

Submission status: Accepted

Solution code:
[N,K] = list(map(int, input().split()))
D = [x for x in input().split()]
while True:
  S = str(N)
  if not any(d in S for d in D):
    break
  N += 1
print(N)

Submission status: Accepted

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

while True:
    for n_str in str(N):
        if int(n_str) in D:
            N += 1
            break
    else:
        print(N)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(str,input().split()))
def judge(x,y):
  X=str(x)
  ret=1
  for i in X:
    if(i in y):
      ret=0
      break
  return ret
while(True):
  if(judge(n,d)==1):
    break
  else:
    n += 1
print(n)

Submission status: Accepted

Solution code:
# 2019/08/17

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

for i in range(n,10*n):
    if any([j in d for j in list(str(i))]):
        continue
    print(i)
    break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Ds = set(input().split())
for i in range(N, 100000):
  s = str(i)
  ng = any(map(lambda c: c in Ds, s))
  if not(ng):
    r = i
    break
print(r)

Submission status: Accepted

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

while True:
    S = str(N)
    if not any(d in S for d in D):
        break
    N += 1
print(N)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dlist = input().split()
flg = True
while flg:
    s = str(n)
    for t in s:
        if t in dlist:
            n += 1
            break
    else:
        flg = False
print(n)

Submission status: Accepted

Solution code:
N,n=map(int,input().split())
dislike=input().split()
count=0
while(1):
  flag=1
  for i in range(n):
    if dislike[i] in str(N+count):
      flag=0
      break
  if flag:
    print(N+count)
    break
  count+=1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d_array = [int(x) for x in input().split()]

for i in range(n, 100000):
    flag = True
    price = str(i)
    for d in d_array:
        str_d = str(d)
        if str_d in price:
            flag = False
    else:
        if flag:
            print(i)
            exit()

Submission status: Accepted

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

ans = N
flg = True
while flg:
    s = str(ans)
    for c in s:
        if c in D:
            ans += 1
            break
    else:
        flg = False
print(ans)