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 = input().split()
D = input().split()
E = [str(x) for x in range(10) if str(x) not in D]
n = len(N)

next_digit = [(str(d), 0) if str(d) not in D else None for d in range(10)]
for i in range(9, -1, -1):
    if next_digit[i] is None:
        j = (i + 1) % 10
        while next_digit[j] is None:
            j = (j + 1) % 10
        if i < j:
            next_digit[i] = next_digit[j]
        else:
            next_digit[i] = (next_digit[j][0], 1)

for i in range(n):
    if N[i] in D:
        carry = 0
        j = i
        reverse_mid = ""
        while j >= 0:
            d = N[j]
            if carry == 1:
                if d == '9':
                    d = '0'
                else:
                    d = chr(ord(d) + 1)
                    carry = 0
            nd, carry0 = next_digit[int(d)]
            reverse_mid += nd
            carry += carry0
            if carry == 0:
                break
            j -= 1
        if carry == 1:
            head = next_digit[1][0]
        else:
            head = N[:j]
        N = head + reverse_mid[::-1] + (E[0] * (n - 1 - i))
        break
print(N)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = input().split()
for n in range(N, 10 * N):
    if all(map(lambda c: c not in D, str(n))):
        print(n)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d=list(map(int, input().split()))
l = [i for i in range(10) if i not in d]
for i in range(n,100000):
    flag=True
    for j in str(i):
        if int(j) in (d):
            flag = False
    if flag:
        print(i)
        break

Submission status: Accepted

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

for i in range(N, N*1000):
    A    = list(str(i))
    flag = True
    for a in A:
        if ( a in D ):
            flag = False
    if( flag == True):
        print(i)
        break

Submission status: Accepted

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list)+1)]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    print(x)
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            i += 1
            ans[j] = use[i]
        mapans = map(str,ans)
        x = int(''.join(mapans))

    print(x)

Submission status: Accepted

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

d = input().split()

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

Submission status: Accepted

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

d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i):
    I = str(i) 
    n = len(I) 
    for j in range(n): 
        if int(I[j]) in d: 
            pass
        else: 
            return False
    return True

for i in range(N, 10**5 + 1): 
    if check(i): 
        print (i) 
        exit()

Submission status: Accepted

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

#使うことのできるリストの作成
d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i): #数値iがdのリストだけで書くことができるかを判定
    I = str(i) #文字列に変換
    # print (I)
    n = len(I) #桁数の取得
    for j in range(n): #全桁で確認
        # print (I[j])
        if int(I[j]) in d: #大丈夫ならスルー
            pass
        else: #一つでも不適ならFalseを返す
            return False
    return True

# print (check(2000))

for i in range(N, 10**5 + 1): #小さい数から全探索
    if check(i): #dの中だけで書けるかをチェック
        print (i) #書くことができるなら出力して終了
        exit()

Submission status: Accepted

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

#使うことのできるリストの作成
d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i): #数値iがdのリストだけで書くことができるかを判定
    I = str(i) #文字列に変換
    # print (I)
    n = len(I) #桁数の取得
    for j in range(n): #全桁で確認
        # print (I[j])
        if int(I[j]) in d: #大丈夫ならスルー
            pass
        else: #一つでも不適ならFalseを返す
            return False
    return True

# print (check(2000))

for i in range(N, 10**5 + 1): #小さい数から全探索
    if i >= N: #大きさを確認
        if check(i): #dの中だけで書けるかをチェック
            print (i) #書くことができるなら出力して終了
            exit()

Submission status: Accepted

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

d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i):
    I = str(i)
    # print (I)
    n = len(I)
    for j in range(n):
        # print (I[j])
        if int(I[j]) in d:
            pass
        else:
            return False
    return True

# print (check(2000))

for i in range(10**5 + 1):
    if i >= N:
        if check(i):
            print (i)
            exit()

Submission status: Accepted

Solution code:
p=input().rstrip().split(' ')
q=input().rstrip().split(' ')
l=[0]*10
for i in range(0,len(q)):
    l[int(q[i])]=1;
for i in range(int(p[0]),1000000000000):
    t=list(str(i))
    G=1;
    for j in range(0,len(t)):
        if l[int(t[j])]==1:
            G=0;
            break;
    if G==1:
        print(i)
        break;

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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())

N,K = LI()
D = [str(i) for i in input().split()]


def main():
    ans = N
    while True:
        for i in range(K):
            # print(list(str(ans)))
            if D[i] in list(str(ans)):
                # print(ans)
                ans += 1
                # ans += 10**max((len(str(ans))-list(str(ans)).index(D[i])-1),0)
                break
            if i == K - 1:
                return ans

print(main())

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dlist = [s for s in input().split()]
ans = n
while True:
    blnOk = True
    for d in str(ans):
        if d in dlist:
            blnOk = False
            break
    if blnOk:
        print(ans)
        exit()
    else:
        ans += 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dlist = [s for s in input().split()]
ans = n
while True:
    blnOk = True
    for d in str(ans):
        if d in dlist:
            blnOk = False
    if blnOk:
        print(ans)
        exit()
    else:
        ans += 1

Submission status: Accepted

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

for i in range(N, 100000):
    flag = True
    for j in str(i):
        if j in D:
            flag = False
            break
    if flag:
        print(i)
        exit()

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
D = [x for x in input().split()]
ans = ''
for i in range(N,N+110000):
    flag = True
    for j in str(i):
        if(j in D):
            flag = False
            break
    if(flag):
        print(i)
        break

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def func(N):
    l=[]
    while(N!=0):
        l.append(N%10)
        N//=10
    return l
for n in range(N,10**6+1):
    l=func(n)
    T=True
    for i in l:
        if i in D:
            T=False
            break
    if T:
        print(n)
        quit()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
s=set(map(int,input().split()))
while len(set([int(c) for c in str(n)])&s)!=0:
	n+=1
print(n)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(input().split())
while N<100000:
    fr=False
    for j in D:
        if j in str(N):
            N+=1
            fr=True
            break
    if fr:
        continue
    else:
        print(N)
        exit()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(input().split())
while sum([i in D for i in list(str(N))])>0:
    N+=1
print(N)

Submission status: Accepted

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

cost = N
while True:
  for i in range(K):
    if str(D[i]) in str(N):
      break
  else:
    print(N)
    exit()
  N += 1

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
d = list(map(str, input().split()))
def search(x):
    count = 0
    for i in d:
        if str(x).find(i) == -1:
            count += 1
    if len(d) == count:
        return True
while True:
   if search(n):
       break
   else:
       n += 1
print(n)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
d = list(map(str, input().split()))
d_n = [i for i in range(10) if i not in d]

def search(x):
    count = 0
    for i in d:
        if str(x).find(i) == -1:
            count += 1
    if len(d) == count:
        return True
while True:
   if search(n):
       break
   else:
       n += 1
print(n)

Submission status: Accepted

Solution code:
[n,k]=[int(_) for _ in input().split()]
d=[int(_) for _ in input().split()]
dt=list({_ for _ in range(10)}-set(d))
def c(n,l):
  for _c in str(n):
    if int(_c) not in l: return False
  return True
while True:
  if c(n,dt): break
  n+=1
print(n)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LS()

  for i in range(n,100001):
    f=True
    for j in str(i):
      if j not in l:
        pass
      else:
        f=False
    if f:
      return i

print(main())

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = set(int(x) for x in 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 test(N):
      return N
    N += 1
  # N は 10の倍数
  x = F(N//10)
  y = min(safe)
  return 10*x + y

answer = F(N)
print(answer)

Submission status: Accepted

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

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

dec_num = [i for i in range(0, 10)]

able_use_num_lis = list(map(str, set(dec_num) - set(num_exclude)))

num_len = len(str(N))

output_list = []

def dfs(cur, num, able_use_num_lis):
    if num != '':
        if int(num) >= N:
            output_list.append(int(num))
    if len(str(N)) + 1 == cur:
        return
    
    for add_num in able_use_num_lis:
        ret = dfs(cur + 1, num + add_num, able_use_num_lis)
    return output_list

print(min(dfs(0, '', able_use_num_lis)))

Submission status: Accepted

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

while True:
  if len( set(str(N)).intersection(D)) == 0:
    print(N)
    exit()
  else:
    N += 1

Submission status: Accepted

Solution code:
import itertools
n, k = map(str, input().split())

ok = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
d = set(map(str, input().split()))
ok.difference_update(d)

ok_list = list(ok)
ok_list.sort()
ans = ""

if ok_list[-1] * len(n) < n:
  ans = ok_list[0] * (len(n) + 1) if ok_list[0] != "0" else ok_list[1] + "0" * len(n)
else:
  for nums in itertools.product(ok_list, repeat=len(n)):
    num = "".join(nums)
    if n <= num:
      ans = num
      break

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
dislike = []
for i in range(0, 10):
	dislike.append(False)
D = list(map(int, input().split()))
for i in range(0, K):
	dislike[D[i]] = True
Y = N
while True:
	flag = True
	for i in range(0, len(str(Y))):
		if dislike[int(str(Y)[i])]:
			flag = False
			break
	if flag:
		print(Y)
		break
	Y += 1

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LS()

  ans=1
  while True:
    if ans>=n:
      s=str(ans)

      f=True
      for x in s:
        if x in l:
          f=False
          break

      if f:
        return ans

    ans+=1

print(main())

Submission status: Accepted

Solution code:

n, m = [ int(v) for v in input().split() ]
num_list = [ v for v in input().split() ]
t = n
while True:
	if all([ ( v not in num_list ) for v in list(str(t))]):
		print(t)
		break
	t += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k = list(map(int,input().split()))
d = list(input().split())

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

Submission status: Accepted

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

dislikes = set(input().split())

price = set(str(n))

while price & dislikes:
    n += 1
    price = set(str(n))

print(n)

Submission status: Accepted

Solution code:
# N<=100000なので愚直にインクリメントしていった最初のやつでいいんじゃないかと思い始めた 繰り上がりとかの場合分けがめんどいし
n, k = map(int, input().split())
nglist = list(input().split())
while True:
    strn = str(n)
    flag = True
    for ng in nglist:
        if ng in strn:
            flag = False
            break
    if flag:
        break
    else:
        n += 1
print(n)

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split(' '))
    d = input().split(' ')
    for i in range(n,10*n+1):
        if not set(list(str(i)))&set(d):
            print(i)
            break

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def equal(n, available):
  return n in available 

def less(n, available):
  return n < sorted(available, reverse=True)[0]

def greater(n, available):
  return n > sorted(available, reverse=True)[0]
  

#less(n, available) == True であること
def upper_next(n, available):  
  for v in sorted(available):
    if n < v:
      return v
  return 1/0

  
n_str, _ = [v for v in input().split()]
n_s = [0]
n_s.extend([int(n_str[i:i+1]) for i in range(len(n_str))])
#print(n_s)
d_s = [int(v) for v in input().split()]

available = set(list(range(10))) - set(d_s)

#print("n", n_s, "d", d_s, "u", available)

min_available = sorted(available)[0]
max_available = sorted(available, reverse=True)[0]
#print(min_available, max_available)
ans = [0]
ans.extend([min_available] * (len(n_s) - 1))

eq = True
for i in range(1, len(n_s)):
  #print(ans)
  if eq:
    if equal(n_s[i], available):
      ans[i] = n_s[i]
      continue
    else:
      eq = False
      #print(n_s[i], available)
      if less(n_s[i], available):
        ans[i] = upper_next(n_s[i], available)
        #残りは最小値詰め
        break
      else:
        for j in range(i - 1, -1, -1):
          #print(ans)
          if ans[j] == max_available:
            ans[j] = min_available
          else:
            #print(ans)
            ans[j] = upper_next(ans[j], available)
            #print(ans)
            break
        break

#print(ans)
begin = 0
if ans[0] == 0:
  begin = 1
ans_val = "".join(map(lambda x:str(x), ans[begin:]))

print(ans_val)

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split(' '))
    d = list(input().split(' '))
    for i in range(n,10*n+1):
        if not set(list(str(i)))&set(d):
            print(i)
            break


main()

Submission status: Accepted

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


Likes = set()


def check(n):
  global Likes
  while n > 0:
    if n%10 not in Likes:
      return False
    else:
      n //= 10
  return True    

def main():
  global Likes
  N,K = map(int, input().split())
  Dn = list(map(int, input().split()))
  Likes = set(range(10))-set(Dn)
  while True:
    if check(N):
      return N
    else:
      N += 1

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

Submission status: Accepted

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

for i in range(N, 100000):
    flag = True
    tmp = i
    for j in reversed(range(len(str(i)))):
        if (tmp // (10 ** j)) in d:
            flag = False
            break
        else:
            tmp = tmp % (10 ** j)

    if flag:
        print(i)
        break

Submission status: Accepted

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



while True:
    a = str(n)
    flag = False
    for i in range(len(d)):
        if str(d[i]) in a:
            flag = True
            n+=1
            break
    if not flag:
        break

print(n)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
b=True
while b:
  b1=False
  l1=list(str(n))
  for i in l1:
    if int(i) in l:
      b1=True
  if b1==False:
    b=False
    print(n)
    break
  else:
    n+=1

Submission status: Accepted

Solution code:
def dfs(i, s, l):
    if i == len(s):
        return ''
    for j in l:
        if j == int(s[i]):
            ans = dfs(i + 1, s, l)
            if ans is not None:
                ans += str(j)
                return ans
        elif j > int(s[i]):
            ans = str(l[0]) * (len(s) - i - 1) + str(j)
            return ans
    return None

n, k = map(int, input().split())
ns = str(n)
d = list(map(int, input().split()))
l = [i for i in range(10) if i not in d]
ans = dfs(0, ns, l)
if ans is None:
    if l[0] == 0:
        ans = str(l[1]) + str(l[0]) * len(ns)
    else:
        ans = str(l[0]) * (len(ns) + 1)
else:
    ans = ans[::-1]
print(ans)

Submission status: Accepted

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

ans = N
while True:
    tmp = ans
    finish = True
    while tmp > 0:
        if tmp % 10 in D:
            finish = False
            break
        tmp //= 10
    if finish:
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
ints = list(map(int, input().split()))
li = list(map(int, input().split()))

number = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
dislike = set(li)
like = number - dislike
for i in range(ints[0], 100000):
    flag = 0
    price = [int(j) for j in str(i)]
    length = len(price)
    for k in range(length):
        if price[k] in like:
            flag += 1
    if flag == length:
        break
print(i)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
d = set(input().split())
while True:
    s = set(list(str(n)))
    if all([i not in d for i in s]):
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  
  l=LI()

  a=0
  while True:
    a+=1
    if a>=n:
      f=True
      for x in list(str(a)):
        if int(x) in l:
          f=False
          break
      if f:
        return a

print(main())

Submission status: Accepted

Solution code:
nk = input().split()
d = input().split()


def hantei(int_siraverukazu):
    lst_siraverukazu = list(str(int_siraverukazu))
    onazi_t_tigau_f = []
    for i in range(int(nk[1])):
        for j in range(len(lst_siraverukazu)):
            if d[i] != lst_siraverukazu[j]:
                onazi_t_tigau_f.append(False)
            else:
                onazi_t_tigau_f.append(True)
    return onazi_t_tigau_f

serch_num  = int(nk[0])
kekka = hantei(serch_num)

while True:
    kekka = hantei(serch_num)
    if True in kekka:
        serch_num += 1
        continue
    if True not in kekka:
        result = serch_num
        break
print(result)

Submission status: Accepted

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

#lst =[]
k = N
"""while k > 0:
    lst.append(k % 10)
    k //= 10
#lst.reverse()"""
#print(lst)


while 1:
    flg = True
    lst = []
    N = k
    while k > 0:
        lst.append(k % 10)
        k //= 10
    lst.reverse()
    #print(lst)
    for i in range(len(lst)):
        if lst[i] in D:
            flg = False
            #print("asd")
            break
    if flg == False:
        k = N
        k += 1
    else:
        break


print(N)

Submission status: Accepted

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

k = N
"""while k > 0:
    lst.append(k % 10)
    k //= 10
#lst.reverse()"""
#print(lst)

while 1:
    flg = True
    lst = []
    N = k
    while k > 0:
        lst.append(k % 10)
        k //= 10
    lst.reverse()
    # print(lst)
    for i in range(len(lst)):
        if lst[i] in D:
            flg = False
            break
    if flg == False:
        k = N
        k += 1
    else:
        break
print(N)

Submission status: Accepted

Solution code:

lst_1 = input().split()

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

lst_N = list(N)

lst_hate = input().split()

flg = True

while 1:

    for i in range(len(lst_N)):

        for j in range(len(lst_hate)):

            if lst_N[i] == lst_hate[j]:
                flg = False
                break

    if flg == True:
        break

    N = ''.join(lst_N)
    N = int(N)
    N += 1
    lst_N = list(str(N))

    flg = True

N = ''.join(lst_N)
print(N)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
d = set(input().split())
for v in range(N, 10 * N):
    if not set(str(v)) & d:
        print(v)
        break

Submission status: Accepted

Solution code:
from itertools import product
N,K = list(map(int,input().split(" ")))
Ds =  list(map(int,input().split(" ")))
nums = [0,1,2,3,4,5,6,7,8,9]
nums = list(set(nums) - set(Ds))

cand = []
for j in range(1,6):
    for i in product(nums, repeat=j):
        i = list(map(str,i))
        temp = "".join(list(i))
        temp = int(temp)
        cand.append(temp)
cand.sort()

for i in cand:
    if i >= N:
        print(i)
        break

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
c=list(map(int,input().split()))
for i in range(a,99999):
    j = list(str(i))
    n=0
    for k in j:
        for d in c:
            if int(k)==d:
                n+=1
    if n==0:
        print(i)
        break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(input().split(' '))
def check(num):
    globals()
    s = str(n)
    for i in d:
        if i in s:
            return True
    return False
while(check(n)):
    n+=1
print(n)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
D = [x for x in range(0,10) if x not in D]
n = len(str(N))
K = 10 - K

def bi(x):
    o = [0]*n
    c = 0
    while x > 0:
        o[c] = x % K
        x //= K
        c += 1
    return o

m = int(str(min(filter(lambda x:x,D)))+str(min(D))*n)

for i in range(K**n):
    o = bi(i)
    j = int(''.join([str(D[x]) for x in o]))
    if N <= j:
        m = min(m,j)

print(m)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
D = list(input().split())
while 1:
        price = str(N)
        flag = True
        for p in price:
                for d in D:
                        if p == d:
                                flag = False
        if flag == True:
                break
        N += 1
print(N)

Submission status: Accepted

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

while True:
    ok = True
    for c in str(n):
        if int(c) in ds:
            ok = False
            break

    if ok:
        print(n)
        break
    else:
        n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=input().split()
stopcode=False
while stopcode==False:
  for i in range(len(str(n))):
    if str(n)[i] in d:
      n+=1
      break
    elif i+1==len(str(n)):
      stopcode=True
      break
print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=n
def judge(m,li):
    ml=list(str(m))
    for i in ml:
        if int(i) in li:
            return True
    return False
while judge(ans,l):
    ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input().split()[0])
a = set(input())

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

print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
*D, = map(int,input().split())
for i in range(N,100000):
    for n in str(i):
        if int(n) in D:
            break
    else:
        break
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#mathをインポート
import math
#n円が金額、嫌いな数がk個。入力
n,k=map(int,input().split(" "))
#嫌いな文字リスト
klist=input().split(" ")
def hantei(n,kl):
    if len(str(n))==4:
        while math.floor(n/1000)==kl or \
        math.floor(n/100)-10*math.floor(n/1000)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    if len(str(n))==5:
        while math.floor(n/10000)==kl or \
        math.floor(n/1000)-10*math.floor(n/10000)==kl or \
        math.floor(n/100)-10*math.floor(n/1000)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or\
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==3:
        while math.floor(n/100)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==2:
        while math.floor(n/10)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==1:
        while n==kl:
            n=n+1
    return int(n)
n2=n
for kl in klist:
    kl=int(kl)
    n=hantei(n,kl)
while n!=n2:
    n2=n
    for kl in klist:
        kl=int(kl)
        n=hantei(n,kl)
print(n)

Submission status: Accepted

Solution code:
n, k = [int(n) for n in input().split()]
d = [n for n in input().split()]
 
while(1):
 
    for l in list(str(n)):
        if l in d:
            break
    else:
        print(n)
        break
 
    n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
    
for x in range(n,10*n):
    flg=True
    for d in str(x):
        if d not in s:
            flg=False
    if flg:
        print(x)
        break

Submission status: Accepted

Solution code:
#n=int(input())
ans=10**6
n,k=map(int,input().split())
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
        
for a in s+['0']:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    x=map(int,[a+b+c+d+e,b+c+d+e,c+d+e,d+e,e])
                    for i in x:
                        if i>=n:
                            ans=min(i,ans)
print(ans)

Submission status: Accepted

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

while(1):

    for l in list(str(n)):
        if l in d:
            break
    else:
        print(n)
        break

    n += 1

Submission status: Accepted

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

for i in range(N, N * 10 + 1):
    check = True
    for n in str(i):
        if int(n) in D:
            check = False
    if check:
        print(i)
        exit()

Submission status: Accepted

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

N_list = list(str(N))
flag = True
cnt = 0

while True:
    N_list = list(str(N+cnt))
    if flag:
        for j, n in enumerate(N_list):
            if int(n) in D:
                cnt += 1
                break
            elif j==len(N_list)-1:
                flag = False
    else:
        break
print(N+cnt)

Submission status: Accepted

Solution code:
import itertools
n,k = map(int,input().split())
a = list(map(str,input().split()))
d = [str(i) for i in range(10)]

for c in a:
    d.remove(c)

res = -1
for l in itertools.product(d,repeat=len(str(n))):
    x = int(''.join(l))
    if x>=n and (res==-1 or x<res):
        res = x
if res != -1:
    print(res)
    exit(0)
for l in itertools.product(d,repeat=len(str(n))+1):
    x = int(''.join(l))
    if x>=n and (res==-1 or x<res):
        res = x
print(res)

Submission status: Accepted

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

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

print(N)