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(str, input().split()))
for i in range(n, 10**5):
    num = str(i)
    for j in range(len(num)):
        if num[j] in d:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n, _ = map(int, input().split())
arr = list(map(str, input().split()))

can_use = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
can_use -= set(arr)

price = set(str(n))

while price - can_use:
    n += 1
    price = set(str(n))

print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D = list(map(str,input().split()))
x = n
while True:
  y = str(x)
  for i in range(len(y)):
    if y[i] in D:
      break
  else:
    ans = x
    break
  x += 1
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=str(n)
flag=False
while flag==False:
    flag=True
    for j in l:
        if s.count(str(j))!=0:
            s=int(s)
            s+=1
            s=str(s)
            flag=False
            break
print(s)

Submission status: Accepted

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

suki =list({0,1,2,3,4,5,6,7,8,9} - set(d))
suki.sort()

result=[]
pay=0
def dfs(pos, pay):
  if pay >= n:
    result.append(pay)
    return result
  elif pos >= 5:
      return '99999'
  
  for i in suki:
    dfs(pos+1, pay*10+i)

dfs(0, 0)
print(min(result))

Submission status: Accepted

Solution code:
def main():
    n, k = list(map(int, input().split()))
    D = set(input().split())
    ans = n
    while not set(list(str(ans))).isdisjoint(D):
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
d = list(input().split())
while True:
    c=0
    for m in range(k):
        if d[m] in str(n):
            c+=1
    if c==0:
        print(n)
        break
    else:
        n+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def hantei(num,list):
    score = 0
    for i in range(len(list)):
        if list[i] in str(num):
            score = +1
    return score                

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

dislike = list(map(str,input().split()))

while True:
    if hantei(N,dislike) == 0:
        break
    N = N + 1
print(N)

Submission status: Accepted

Solution code:
from collections import Counter


def ok(n, D):
    # Dに含まれる数字をnで使っていたらFalse
    counter = Counter(str(n))
    for d in D:
        if counter[str(d)] > 0:
            return False
    return True


def main():
    N, K = list(map(int, input().split(' ')))
    D = list(map(int, input().split(' ')))
    while not ok(N, D):
        N += 1
    print(N)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

while set(list(str(n))) & d != set():
    n += 1

print(n)

Submission status: Accepted

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

D=set(input().split())

while set(list(str(n)))&D!=set():
    n+=1

print(n)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n, k = ns()
    d = sys.stdin.readline().split()

    s_n = str(n)

    flg = True
    while flg:
        s_n = str(n)

        flg_tmp = True
        for di in d:
            if di in s_n:
                flg_tmp = False
                break

        flg = not flg_tmp
        n += 1

    print(n - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    n, k = map(int, readline().split())
    d = {int(i) for i in readline().split()}
    dq = deque()
    dq.append(0)
    cnd = []
    while len(dq)>0:
        v = dq.popleft()
        for i in range(10):
            if i in d:
                continue
            cnd.append(v*10+i)
            dq.append(v*10+i)
        if n <= dq[-1]:
            break

    ans = 0
    for i in cnd:
        if n <= i:
            print(i)
            break
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    n, k = map(int, readline().split())
    d = {int(i) for i in readline().split()}
    dq = deque()
    cnd = []
    for i in range(10):
        if i in d:
            continue
        dq.append(i)
        cnd.append(i)

    while len(dq)>0:
        v = dq.popleft()
        for i in range(10):
            if i in d:
                continue
            cnd.append(v*10+i)
            dq.append(v*10+i)
        if n <= dq[-1]:
            break

    ans = 0
    for i in cnd:
        if n <= i:
            print(i)
            break
if __name__ == '__main__':
    main()

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,_,*d=open(0).read().split()
n=int(n)
while 1:
 if all(d not in str(n)for d in d):exit(print(n))
 n+=1

Submission status: Accepted

Solution code:
n,_,*d=open(0).read().split()
n,d=int(n),set(d)
while 1:
 if not d&set(str(n)):exit(print(n))
 n+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k, *d = open(0).read().split()
n, d = int(n), set(d)
while True:
  if not d & set(str(n)):
    exit(print(n))
  n += 1

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
D = list(map(str,input().split()))
for i in range(n,10**7):
    for j in str(i):
        if j in D:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
D = set(map(str,input().split()))
for i in range(n,10**7):
    for j in str(i):
        if j in D:
            break
    else:
        print(i)
        break

Submission status: Accepted

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

tmp = set(['0','1','2','3','4','5','6','7','8','9'])

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

Submission status: Accepted

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

curr_num = N
while True:
    n_str = str(curr_num)
    for d in dl:
        if d in n_str:
            curr_num += 1
            break
    else:
        print(curr_num)
        break

Submission status: Accepted

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

candidate_num=set(['0','1','2','3','4','5','6','7','8','9'])-d

while True:
    if set(list(str(n)))<=candidate_num:
        print(n)
        exit()
    else:
        n+=1

Submission status: Accepted

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

tmp = set(['0','1','2','3','4','5','6','7','8','9'])

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

Submission status: Accepted

Solution code:
def ret_num(num, val):
  for i in num:
    if i > val:
      return i

def check(num, val):
  while val > 0:
    if val % 10 not in num:
      return False
    val//=10
  return True
    
all_num=[0,1,2,3,4,5,6,7,8,9]
(val, dis)=[int(x) for x in input().split()]
dis_num=[int(x) for x in input().split()]
num=[]
for i in all_num:
  if i not in dis_num:
    num.append(i)
while True:
  if check(num, val):
    print(val)
    break
  else:
    val+=1

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
n=str(n)
cand=[]
flag=True
for i in range(10):
    if not i in lis:
        cand.append(i)
mx=""
for i in range(len(n)):
    mx+=str(cand[-1])
if int(n)>int(mx):
    flag=False
stri=""
if flag==False:
    if 0 in cand:
        v=str(cand[1])
        stri+=v
        for i in range(len(n)):
            stri+="0"
        
    else:
        v=str(cand[0])
        for i in range(len(n)+1):
            stri+=v
    print(stri)
else:
    for i in range(int(n),10000):
        y=str(i)
        cou=0
        for j in range(len(y)):
            if int(y[j]) in cand:
                cou+=1
        #print(cou)
        if cou==len(y):
            print(y)
            sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(input().split())
for i in range(N,10*N+1):
    ans = True
    for j in D:
        if str(i).count(j) > 0:
            ans = False
            break
    if ans == True:
        print(i)
        break

Submission status: Accepted

Solution code:
class A:

    def solve(self):
        [a, b, c] = sorted([int(x) for x in input().split(" ")])
        if a == 5 and b == 5 and c == 7:
            print("YES")
        else:
            print("NO")

class B:

    def solve(self):
        [n, l] = [int(x) for x in input().split(" ")]

        strings = []
        for r in range(n):
            strings.append(input())

        sorted_strings = sorted(strings)

        print("".join(sorted_strings))

class C:

    def fix(self, final_amount, likes):
        i = 0
        import bisect as b
        changed = False
        for i,x in enumerate(reversed(final_amount)):
            real_index = len(final_amount) - i - 1
            ind = b.bisect_right(likes, int(x))
            if ind != len(likes):
                final_amount[real_index] = str(likes[ind])
                changed = True
                break

        if not changed:
            ind = b.bisect_right(likes, 0)
            final_amount = [str(likes[ind])] + final_amount
            i = 1
        else:
            i = len(final_amount) - i - 1

        while i < len(final_amount):
            final_amount[i] = str(likes[0])
            i += 1

        return final_amount

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        dislikes = [int(x) for x in input().split(" ")]

        likes = []
        for r in range(10):
            if r not in dislikes:
                likes.append(r)

        import bisect as b

        final_amount = []
        sn = str(n)
        for ind in range(len(sn)):
            c = sn[ind]
            i = b.bisect_left(likes, int(c))
            if i == len(likes):
                prev_len = len(final_amount)
                final_amount = self.fix(final_amount, likes)
                final_amount += [str(likes[0]) for r in range(len(sn) - prev_len)]
                break

            if str(c) != str(likes[i]):
                final_amount.append(str(likes[i]))
                final_amount += [str(likes[0]) for r in range(len(sn) - len(final_amount))]
                break

            final_amount.append(str(likes[i]))

        print("".join(final_amount))

C().solve()

Submission status: Accepted

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

num = []

for i in range(10):
  if i not in D:
    num.append(str(i))
ans = 10**18
for i in product(num,repeat=len(str(N))):
  money = int(''.join(list(i)))
  if N <= money :
    ans = min(ans,money)
if ans == 10**18:
  for i in product(num,repeat=len(str(N))+1):
    money = int(''.join(list(i)))
    if N <= money :
      ans = min(ans,money)
print(ans)

Submission status: Accepted

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

values = [0]
idx = 0
while True:
  base = values[idx] * 10
  for a in available:
    n = base + a
    if n >= N:
      print(n)
      quit()
    values.append(n)
  idx += 1

Submission status: Accepted

Solution code:
from itertools import product
n, k = input().split()
a = list(input().split())
l = set([str(i) for i in range(10)]).difference(a)
ni = int(n)
ans = int('99'+n)
for j in range(len(n), len(n)+2):
    for i in product(l, repeat=j):
        t = int(''.join(i))
        if t >= ni:
            ans = min(t, ans)
print(ans)

Submission status: Accepted

Solution code:
inf = 10**18
mod = 10**9+7

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


n,k = map(int, input().split())
d = list(input().split())
ans = n
for i in range(n, n*10+1):
    tmp = str(i)
    ok = True
    for c in tmp:
        if c in d:
            ok = False
            break
    if ok:
        ans = i
        break
print(ans)

Submission status: Accepted

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

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

print(N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque
n,k = map(int,input().split())
d = set(list(map(int,input().split())))
a = list({0,1,2,3,4,5,6,7,8,9} - d)
a.sort()
que = deque()
que.append(0)

while que:
    ans = que.popleft()
    if ans >= n:
        print(ans)
        exit()
    for i in a:
        que.append(ans*10 + i)

Submission status: Accepted

Solution code:
[n,k] = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
dic = {}
iter = 0
for i in range(10):
    try:
        if i != d[iter]:
            dic[str(i)] = 1
        else:
            dic[str(i)] = 0
            iter += 1
    except:
        dic[str(i)] = 1
        pass

for i in range(n,10 ** 5):
    tmp = 1
    cand = str(i)
    for j in range(len(cand)):
        tmp *= dic[cand[j]]
    if tmp == 1:
        print(cand)
        break

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
D=n1()

while True:
    t=str(n)
    for i in D:
        if t.count(str(i))>0:
            n+=1
            break
    else:
        break
print(n)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
D=n1()

t=tuple(int(i) for i in str(n))

D2=[i for i in range(10) if not i in D]

ite=list(itertools.product(D2,repeat=(len(str(n)))))

index=bisect_left(ite,t)
if index==len(ite):
    if D2[0]==0:
        ans="".join([str(D2[1])]+["0"]*len(str(n)))
    else:
        ans="".join([str(D2[0])]*(len(str(n))+1))
else:
    ans="".join([str(i) for i in ite[bisect_left(ite,t)]])
print(ans)

Submission status: Accepted

Solution code:
from itertools import*

p, _ = map(int, input().split())
nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - {int(i) for i in input().split()}
for i in count(p):
    if {int(d) for d in str(i)} - nums == set():
        print(i)
        break

Submission status: Accepted

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

def contain(n):
  ns=list(str(n))
  for c in ns:
    if int(c) in dset:
      return True
  return False

for i in range(N,100000):
  if not contain(i):
    print(i)
    break
else:
  print(-1)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
num_list = list(map(str,input().split()))
for i in range(n, 100005):
    j = str(i)
    flag = True
    for k in range(len(j)):
        if j[k] in num_list:
            flag = False
    if flag:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,k = list(map(int, input().split()))#n = 払いたい金額  k = 嫌いな数字の個数（len(ln)）
ln = list(map(int, input().split()))
pay = n

while True:
    counter = 0
    for i in str(pay):
        if int(i) in ln:
            counter +=1
    if counter == 0:
        print(pay)
        break
    else:
        pay += 1

Submission status: Accepted

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

canidates = [i for i in range(10) if i not in d]

ans = 10**9
def bfs(s):
    global ans
    if len(s) > len(str(n))+1:
        return
    if len(s) > 0:
        res = int(s)
        if res >= n and res < ans:
            ans = res
    for i in canidates:
        bfs(s+str(i))
bfs('')
print(ans)

Submission status: Accepted

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

for i in range(n,n*10+1):
  s=str(i)
  for p in d:
    if p in s:
      break
  else:
    print(i)
    break

Submission status: Accepted

Solution code:
fn=str
n,k=map(int, input().split())
ds=list(map(fn, input().split()))
while any(i in fn(n) for i in ds):
  n+=1
print(fn(n))

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
ds=list(map(str, input().split()))
while any(i in str(n) for i in ds):
  n+=1
print(str(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = input().split()
i = 0
while i < 1:
  i = 1
  for n in str(N):
    if n in D:
      i = 0
  N += 1
print(N - 1)

Submission status: Accepted

Solution code:
n, k = input().split()
strN = list()
for num in n:
    if num not in strN: strN.append(int(num))
sorted(strN)
N = int(n)
K = int(k)
nonFavDigits = input().split()
NonFavDigits = list()
for nFD in nonFavDigits:
    NonFavDigits.append(int(nFD))
Digits = list(range(0,10))
for dig in range(0,10):
    if dig in NonFavDigits: Digits.remove(dig)
flag = 0
if(all(x in Digits for x in strN)): flag = 1
if(flag):   print(N)
else:
    finalNum = N+1
    strFN = list()
    for num in str(finalNum):
        if num not in strFN: strFN.append(int(num))
    while not all(x in Digits for x in strFN):
        finalNum+=1
        strFN = list()
        for num in str(finalNum):
            if num not in strFN: strFN.append(int(num))
    print(finalNum)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,K  = IL()
D = IL()

for i in range(N,100000):
  flag = 1
  for j in str(i):
    if int(j) in D:
      flag = 0
  if flag:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？



n,k=mii()
p=limii()
q=[0,1,2,3,4,5,6,7,8,9]
arr=[]
for i in q:
    if i not in p:
        arr.append(i)
ans=10**100
for i in range(len(list(str(n))),6):
    for mat in list(product(arr, repeat=i)):
        if int("".join([str(l) for l in mat]))>=n:
            ans=min(ans,int("".join([str(l) for l in mat])))
            
print(ans)

Submission status: Accepted

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

for i in range(N, 10**18):
    str_i = str(i)
    flag = True
    for d in D:
        if d in str_i:
            flag = False
            break
    if flag:
        print(i)
        break

Submission status: Accepted

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


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

Submission status: Accepted

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

"""
嫌いな数字がk個あり，それがd1~dk
N円のものを買うときの最低値
入力:
n k
d1-dk
"""


def contain(s, l):
    for i in range(len(s)):
        for j in l:
            if s[i] == j:
                return False
    else:
        return True


def main():
    n, k = map(str, input().split())
    kirai_num_list = input().split()

    if contain(n, kirai_num_list):
        print(n)
    else:
        while True:
            n = int(n) + 1
            if contain(str(n), kirai_num_list):
                print(str(n))
                sys.exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

N = l[0]
K = l[1]

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

for value in range(100001):
  result = 0
  if value >= N:
    flg = 1
    for num in s:
      if str(num) in str(value):
        flg = 0
        break
    if flg == 1:
      result = value
      break
print(result)

Submission status: Accepted

Solution code:
K, N = map(int, input().split())
liked_num = [0,1,2,3,4,5,6,7,8,9]
disliked_num = list(map(int, input().split()))
for s in disliked_num:
    liked_num.remove(s)
cnt = K
flag = 1
while flag:
    not_n = 1
    for i in str(cnt):
        if not int(i) in liked_num:
            not_n = 0
            break
    if not_n:
        break
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(input().split())
for i in range(n, 10*n):
    for c in str(i):
        if c in d:
            break
    else:
        print(i)
        break

Submission status: Accepted

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

a = []
for i in range(10):
    if i not in d:
        a.append(i)

check = set(a)
for i in range(10**5):
    if i >= n and set(map(int, list(str(i)))) <= set(a):
        print(i)
        exit()

Submission status: Accepted

Solution code:
from collections import deque
n , k = map(int,input().split())
d = set(list(map(int,input().split())))
kouho =list({0,1,2,3,4,5,6,7,8,9} - d)
kouho.sort()

p = deque()
p.append(0)

while p:
    now = p.popleft()
    if now >= n:
        print(now)
        exit()
    for i in kouho:
        p.append(now*10+i)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    if len([n_ for n_ in str(n) if n_ in ds]) == 0:
        break
    else:
        n += 1
print(n)

Submission status: Accepted

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

for i in range(N,N*10):
    c=0
    for j in str(i):
        if int(j) not in number:
            c=1
            break
    if c==0:
        print(i)
        break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  N, K = map(int, input().split())
  D = list(input())
  
  x = N
  while True:
    if all(y not in D for y in list(str(x))):
      if x >= N:
        print(x)
        break
    x += 1

Submission status: Accepted

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

y = N
while True:
    if all(a not in D for a in list(str(y))):
        if y >= N:
            print(y)
            break
    y += 1

Submission status: Accepted

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

y = 1
while True:
    if all(a not in D for a in list(str(y))):
        if y >= N:
            print(y)
            break
    y += 1

Submission status: Accepted

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