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(input().split())

for x in range(N,10**6):
  x = str(x)
  judge = 1
  for xi in x:
    if(xi in D):
      judge = 0 
  if(judge == 1):
    ans = x
    break
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
n, k = map(int, input().split())
 
hate = list(map(int, input().split()))
 
while True:
    for c in str(n):
        if int(c) in hate:
            break
    else:
        print(n)
        exit()
    n += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = [i for i in range(10)]
[d.remove(int(x)) for x in input().split()]
n_len = len(str(n))

def rec_define_digit(s):
    v = int(s)
    # print(s)
    if v >= n:
        return v
    ans = 999999
    if len(s) >= n_len + 2:
        return ans
    for i in d:
        ans = min(rec_define_digit(s + str(i)), ans)
    return ans

print(rec_define_digit("0"))

Submission status: Accepted

Solution code:
import itertools

n, k = map(int, input().split())
d = [i for i in range(10)]
[d.remove(int(x)) for x in input().split()]
n_len = len(str(n))

ans = -1
for x in itertools.product(d, repeat=n_len):
    v = int("".join([str(i) for i in list(x)]))
    # print(v)
    if v >= n:
        if ans < 0 or ans > v:
            ans = v

if ans < 0:
    for x in itertools.product(d, repeat=n_len+1):
        v = int("".join([str(i) for i in list(x)]))
        # print(v)
        if v >= n:
            if ans < 0 or ans > v:
                ans = v

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

n, k = map(int, input().split())

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

while True:
    for c in str(n):
        if int(c) in hate:
            break
    else:
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(n,10*n+1):
    m =list(map(int,str(i)))
    no = 0
    for j in range(len(m)):
        if m[j] in a:
            no = 1
            break
    if no == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)

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

ans = []
def dfs(p:str):
    if int(p)>=n:
        ans.append(int(p))
        return

    if len(p)>len(str(n))+1:
        return

    for i in range(10):
        if not i in D:
            dfs(p+str(i))

for i in range(10):
    if not i in D:
        dfs(str(i))

print (min(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    D=set(input().split())
    for i in range(N,10**7):
        if not set(str(i))&D:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
b = {0,1,2,3,4,5,6,7,8,9}-set(a) #使用可能な数字の集合
while set([int(i) for i in list(str(n))])-b !=set() : # 使用可能な数字のみでなければ
    n += 1
print(n)

Submission status: Accepted

Solution code:
import copy
n,k = map(int,input().split())
d = input().split()
nd = list(map(str,range(10)))
for i in d:
  nd.remove(i)
l = len(str(n))
if "0" in nd:
  a1 = 1
else:
  a1 = 0
alist = nd[a1:]
for _ in range(l-1):
  tlist = []
  for i in alist:
    for j in nd:
      tlist.append(i+j)
  alist = copy.copy(tlist)
alist.append(nd[a1]+nd[0]*l)
for i in alist:
  if n <= int(i):
    print(i)
    exit()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = input().replace(" ","")
for i in range(n,10**9):
  check = True
  for j in str(i):
    if j in d:
      check = False
      break
  if check:
    print(i)
    break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
lis = []
for i in range(10):
    if not i in d:
        lis.append(i)
inf = 1001001001
ans = inf
def dfs(s, n):
    if len(s) >= len(str(n)) + 2:
        return
    if len(s) > 0 and int(s) >= n:
        global ans
        ans = min(ans, int(s))
    else:
        for i in lis:
            dfs(s + str(i), n)
dfs("", n)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
D = set(map(str,input().split()))
res = N
while 1:
    flg = 0
    for char in str(res):
        if char in D:
            flg = 1
    if flg == 1:
        res += 1
        continue
    break
print(res)

Submission status: Accepted

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

while True:
    s = str(n)
    f = 1
    for i in range(len(s)):
        if s[i] in d:
            f = 0
        else:
            pass

    if f:
        print(s)
        break
    else:
        n += 1

Submission status: Accepted

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

while (1):
   c = [x for x in str(n)]

   ok = 1
   for x in c:
      if x in d:
         ok = 0
         break

   if ok == 1:
      break

   n += 1

print(n)

Submission status: Accepted

Solution code:

N,K=map(int,input().split())
D=input().split()
n=N
while 1:
  flg=True
  for i in range(K):
    if D[i] in list(str(n)):
      flg=False
     
  if flg:
    break
  else:
    n+=1
print(n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dislike = list(map(int, input().split()))
for i in range(n,10**18):
    a = str(i)
    # print(a)
    flag = True
    for j in range(len(a)):
        # print(a[j])
        for k in dislike:
            # print(k)
            if int(a[j]) == k:
                flag = False
                break
        if flag == False:
            break
    if flag == True:
        print(i)
        break

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:
            n+=1
            break
    else:
        print(n)
        exit()

Submission status: Accepted

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy
#N=int(input())
N,K=map(int,input().split())
D=set(input())
while len(set(str(N))&D)>0:
    N+=1
print(N)

Submission status: Accepted

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

    pay = N
    while True:
        if any(c in D for c in map(int, str(pay))):
            pay += 1
            continue
        print(pay)
        return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy
#N=int(input())
N,K=map(int,input().split())
D=list(map(int,input().split()))
for i in range(N,100000):
    t=set(map(int,list(str(i))))
    temp=D+list(t)
    temp2=set(temp)
    if len(temp)==len(temp2):
        #print(temp)
        #print(temp2)
        print(i)
        exit()

Submission status: Accepted

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    digits = {x for x in range(10)}
    digits -= D
    # print(digits)
    digits = sorted(digits)

    def dfs(pay):
        if pay >= N:
            return pay

        np = pay * 10

        ret = 1 << 60
        if np == 0 and 0 in digits:
            for d in digits:
                if d == 0: continue
                ret = min(ret, dfs(np + d))
        else:
            for d in digits:
                ret = min(ret, dfs(np + d))
        return ret

    print(dfs(0))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
num = set(map(int,input().split()))
ans=0
for i in range(n,10*n):
  for j in range(len(str(i))):
    if int(str(i)[j]) in num:
      if j==0:
        i = (int(str(i)[0])+1)*(10**(len(str(i))-1))   
      break
    if j ==len(str(i))-1:
      ans=i
  if ans!=0:
    break
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n, k = list(map(int, input().split()))
dl = list(map(int, input().split()))
target = []
for i in range(10):
    if i not in dl:
        target.append(i)
# print(target)
ansl = []
for R in range(1, 6):
    for bit in product(target, repeat=R):
        t = 0
        for i, b in enumerate(bit):
            t += (10**i)*b
        # print(bit, t)
        if t >= n:
            ansl.append(t)
print(min(ansl))

Submission status: Accepted

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

digitlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for d in D:
    digitlist.remove(d)

Keta = len(str(N))
Ans = ''


def clear(X):
    if len(X) == Keta:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear(X)
            X = X[:-1]


def clear2(X):
    if len(X) == Keta+1:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear2(X)
            X = X[:-1]



clear(Ans)
clear2(Ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

init = [str(i) for i in range(10) if i not in D and i != 0]
use = [str(i) for i in range(10) if i not in D]
q = deque(init)
ans = []
while q:
    num = q.pop()
    if int(num) >= N:
        ans.append(num)
        continue
    for u in use:
        q.append(num + u)

print(min(list(map(int, ans))))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
num = n
while True:
    is_match = True
    for c in str(num):
        if int(c) in d:
            is_match = False
            break
    if is_match:
        break
    num += 1
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
flag=0
m=n
while (flag==0):
    str_m=list(str(m))
    for j in d:
        if(j in str_m):
            m+=1
            flag=2
            break
    if(flag==2):
        flag=0
        continue
    else:
        flag=1

print(int(m))

Submission status: Accepted

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

while(1):
    n_str = list(str(n))
    if sum([i in ds for i in n_str]) == 0:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
flag = False
while True:
  K_str = str(K)
  for i in range(len(K_str)):
    for j in range(len(D)):
      if K_str[len(K_str)-1-i]==str(D[j]):
        flag=False
        break
      if j==len(D)-1:
        flag = True

    if not flag:
      break

  if flag:
    break
  K+=1

print(K)

Submission status: Accepted

Solution code:
import sys
import numpy as np
input=sys.stdin.readline

n,k=map(int,input().split())
d=list(map(int,input().split()))
res=[]
for i in range(10):
  if i not in d:
    res.append(i)
ans=0
ansmax=0
ansmin=0
n_s=str(n)
l=len(n_s)
M=max(res)
for i in range(l):
    ansmax+=M*10**(l-i-1)
if n>ansmax:
    if res[0]!=0:
        ans=res[0]*10**l
    else:
        ans=res[1]*10**l
    for i in range(l):
        ans+=res[0]*10**(l-i-1)
    print(ans)
    exit()
res=np.array(res)
flag=False
for i in range(l):
    j=n//(10**(l-i-1))
    if not flag:
        if j not in res:
            p=np.searchsorted(res,j, side="left")
            m=res[p]
            ans+=m*10**(l-i-1)
            flag=True
            continue
        else:
            ans+=j*10**(l-i-1)
    if flag:
        ans+=res[0]*(10**(l-i-1))
    n=n%(10**(l-i-1))
print(ans)

Submission status: Accepted

Solution code:
N,K= map(int,input().split())
D = [int(j) for j in input().split()]
D2 = list(set([i for i in range(0,10)])-set(D))
def f(N,D):
    if len(set([int(i) for i in list((str(N)))])&set(D))==0:
        return True
    else:
        return False
if len(D2) ==0:
    print(N)
else:
    while not f(N,D):
        N+=1
print(N)

Submission status: Accepted

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

ansl = []
def dfs(s):
  if len(s) < len(str(N))+1:
    for i in l:
      new = s+str(i)
      ansl.append(int(new))
      dfs(new)
dfs("")
ansl.sort()
for i in ansl:
  if i >= N:
    print(i)
    break

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, _ = readnums()
    d = set(readstrs())
    for i in range(N, 100000):
        for digit in tuple(str(i)):
            if digit in d:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

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

use = [i for i in range(10)]

for _d in d:
    use.remove(_d)


while True:
    ok = True
    s = str(n)
    for i in range(len(s)):
        if int(s[i]) not in use:
            ok = False
            break

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

Submission status: Accepted

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

D = list(map(int,input().split()))
OK = []
for i in range(10):
  if i not in D:
    OK.append(str(i))
#print(OK)
sn = str(N)
l = len(sn)

ans = N*1
Flag = 0
while Flag == 0:
  sans = str(ans)
  if all(sans[i] in OK for i in range(len(sans))):
    Flag = 1
  else:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,1000000):
  s=str(i)
  ok=True
  t_str=""
  for ss in s:
    if int(ss) in d:
      ok=False
      break
    t_str+=ss
  if ok:
    print(int(t_str))
    exit(0)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    D = set(list(map(int, input().split())))

    def dfs(L):
        if len(L) == 6:
            return

        for i in range(10):
            if i not in D:
                L.append(str(i))
                res = int("".join(L))
                if res >= n:
                    ans.append(res)
                dfs(L)
                L.pop()

        return ans

    ans = []
    dfs([])
    ans.sort()
    for i in ans:
        if n <= i:
            print(i)
            break


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

for i in range(N,10**9):
    S=str(i)
    ok=True
    for s in S:
        if int(s) in D:
            ok=False
    if ok:
        ans=i
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


def ok(s):
    for c in s:
        if c in D:
            return False
    return True


i = N
while True:
    s = str(i)
    if ok(s):
        print(s)
        exit()
    i += 1

Submission status: Accepted

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

ans = float("INF")
for v in itertools.product(d, repeat=len(str(n))):
  if v[0] != "0" and int("".join(v)) >= n:
    if ans > int("".join(v)): ans = int("".join(v))
if ans == float("INF"):
  for v in itertools.product(d, repeat=len(str(n))+1):
    if v[0] != "0" and int("".join(v)) >= n:
      if ans > int("".join(v)): ans = int("".join(v))
print(ans)

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    d = set(input().split())
    while True:
        if len(set(str(n))&d) == 0:
            print(n)
            return 0
        n += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
d=[int(i) for i in input().split()]
for i in range(1,100001):
    if i<n:
        continue
    now=str(i)
    for j in now:
        if int(j) in d:
            break
    else:
        print(now)
        sys.exit()

Submission status: Accepted

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

for i in range(N, 100 * N):
    if set(list(str(i))) <= D:
        print(i)
        exit()

Submission status: Accepted

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

ans = n
while True:
    for i in list(map(int, str(ans))):
        if i in D:
            break
    else:
        print (ans)
        exit ()

    ans += 1

Submission status: Accepted

Solution code:
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))

# 1. 初期化
ok_lst = [x for x in range(0, 10) if x not in D]
ok_lst.sort(reverse = True)
stack = deque([x for x in ok_lst if x != 0])
ans_list = []

while len(stack) > 0:
    # 2. 現在の情報の取得
    # 今回は現在の数字
    now_num = stack.pop()
    # 3. 処理
    # もしnow_numが条件の値以上になったらans_listに記録し，数値を足すとまずいのでcontinueで防ぐ
    if now_num >= n:
        ans_list.append(now_num)
        continue
    # 4. 更新
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        next_num = int(next_num)
        stack.append(next_num)

print(min(ans_list))

Submission status: Accepted

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

ans = n
flag = True
while flag:
  flag = False
  for x in d:
    if x in str(ans):
      ans += 1
      flag = True
      continue
      
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
for j in range(n, 100000):
    flg=False
    for s in set(str(j)):
        if s in d:
            flg=True
            break
    if flg==False:
        print(j)
        break

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
n,k = ma()
D = set(input().split())
for i in range(n,10*n+1):
    if set(list(str(i))) & D:
        pass
    else:
        print(i)
        exit()

Submission status: Accepted

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

yet=True
while yet:
    yet=False
    for i in list(str(n)):
        if i in d:
            yet=True
            break
    n+=1

print(n-1)

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    dislike = input().split()

    start = n
    while True:
        # print(start)
        for digit in str(start):
            if digit in dislike:
                start += 1
                break
        else:
            print(start)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc042/tasks/arc058_a

n, k = map(int, input().split())

nums = list(set([i for i in range(10)]) - set([int(i) for i in input().split()]))


def dfs(nums, t, n, path):
    if int(t) >= n:
        path.append(int(t))
        return
    if len(t) > 7:
        return
    for num in nums:
        dfs(nums, t + str(num), n, path)
path = []
dfs(nums, '0', n, path)
path.sort()
ans = path[0]
print(ans)

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:
        break
print(n)

Submission status: Accepted

Solution code:
def main():
 num = list(map(int,input().split()))
 bad = list(map(str,input().split()))

 while True :
  flg=0
  
  for i in range(0,len(str(num[0]))):
   stnum=str(num[0])
   if stnum[i] in bad:
    flg=1
    break
   
  if flg==1:
   num[0]+=1
   continue
  else:
   break
  
 print(num[0])

main()

Submission status: Accepted

Solution code:
def main():
 num = list(map(int,input().split()))
 bad = list(map(int,input().split()))

 while True :
  flg=0
  
  for i in range(0,len(str(num[0]))):
   stnum=str(num[0])
   if int(stnum[i]) in bad:
    flg=1
    break
   
  if flg==1:
   num[0]+=1
   continue
  else:
   break
  
 print(num[0])

main()

Submission status: Accepted

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

price = N

flag = "like"
ans_flag = 0

while ans_flag == 0:
  for i in range(len(str(price))):
    if int(str(price)[i]) in d:
      flag = "dislike"
  if flag == "dislike":
    price +=1
    flag ="like"
  else:
    ans_flag = 1
print(price)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

"""
lim = 2*10**5   #必要そうな階乗の限界を入力

#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod

#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod

"""

N, K = MAP()
D = LIST()

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

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:
        break
print(N)

Submission status: Accepted

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

n = str(N)
N_keta = len(n)

for i in n:
    if int(i) not in UN:
        break
else:
    print(N)
    exit()

ex_0 =  [i for i in UN if i > 0]

if N_keta == 1:
    if N < max(UN):
        _11 =[i for i in UN if i > N]
        print(min(_11))
    else:
        print(min(ex_0) * 10 + min(UN))

if N_keta == 2:
    if N < max(UN) * 11:
        for i in UN:
            for j in UN:
                _2 = i * 10 + j
                if  _2 > N:
                    print(_2)
                    exit()
    else:
        print(min(ex_0) * 100 + min(UN) * 11)

if N_keta == 3:
    if N < max(UN) * 111:
        for i in UN:
            for j in UN:
                 for k in UN:
                     _3 = i * 100 + j * 10 + k
                     if _3 > N:
                         print(_3)
                         exit()
    else:
        print(min(ex_0) * 1000 + min(UN) * 111)

if N_keta == 4:
    if N < max(UN) * 1111:
        _4 = [i for i in UN if i >= int(n[0])]
        for i in _4:
            for j in UN:
                for k in UN:
                    for l in UN:
                        _41 = i * 1000 + j * 100 + k * 10 + l
                        if _41 > N:
                            print(_41)
                            exit()
    else:
        print(min(ex_0) * 10000 + min(UN) * 1111)

Submission status: Accepted

Solution code:
def main():
    from itertools import combinations_with_replacement,permutations
    n, k = map(int, input().split())
    *d, = input().split()
    m = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} - set(d)
    m = list(m)
    m.sort()
    mm = ""
    if m[0] != "0":
        mm = m[0]
    else:
        mm = m[1]

    l = len(str(n))
    t = set()
    for s in combinations_with_replacement(m, l):
        for xx in permutations(s):
            w = "".join(xx)
            ww = mm + w
            t.add(int(w))
            t.add(int(ww))

    t = list(t)
    t.sort()
    for x in t:
        if x >= n:
            print(x)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

while True:
    l = str(n)
    for i in l:
        if i in s:
            break
    else:
        break
    n += 1
print(n)

Submission status: Accepted

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

for i in range(N, 100001):
    if set(list(str(i))) & set(D):
        gg = 1
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
import numpy as np
N, _ = map(int, input().split())
D = np.bincount(tuple(map(int, input().split())), minlength=10)
while True:
    n = N
    while n:
        if D[n % 10]:
            break
        n //= 10
    else:
        break
    N += 1
print(N)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N, K = getNM()
intlist = [i for i in range(10)]
D = getList()
for i in D:
    if i in D:
        # 嫌いな数字を消す
        intlist.pop(intlist.index(i))

anslist = []
# intlist内の数字でできる５桁以内の数字を全列挙（５桁の数字も列挙するのは無駄な気もする）
# dfsで解いてる人はあんまりいない
# 基本的に全探索
def dfs(i, num):
    anslist.append(num)
    # num < Nの条件で計算量を制限
    if i < 5 and num < N:
        for j in intlist:
            newnum = int(str(num) + str(j))
            dfs(i + 1, newnum)

for i in intlist:
    if i != 0:
        dfs(1, i)

anslist.sort()

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