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:
def main():
    N, K = map(int, input().split())
    D = list(input().split())
    
    for i in range(N,100000):
        a = str(i)
        flag = True
        for d in D:
            if d in a:
                flag = False
                break
        if flag:
            print(i)
            exit()



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def is_bad_nums(j: int, d: []) -> bool:
    while j:
        if j % 10 in d:
            return True
        j //= 10
    return False


def answer(n: int, k: int, d: []) -> int:
    for i in range(n, 100000):
        if is_bad_nums(i, d):
            continue
        return i


def main():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    print(answer(n, k, d))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
num = str(list(set(num) ^ set(D)))

ans = str(N)
clear = 0

while clear == 0:
    for i in range(len(ans)):
        if not ans[i] in num:
            break
        if i == len(ans) - 1:
            clear += 1  
    ans = str(int(ans) + 1)

print(int(ans) - 1)

Submission status: Accepted

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

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

def ok(x):
    while x:
        if x % 10 in D:
            return False
        x //= 10
    return True

for i in range(N,100000):
    if ok(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
def price(N,K):
    Kn = input().split()
    Flag = False

    for i in range(N,10*N,1):
        value = str(i)
        for j in range(K):
            if(Kn[j] not in value):
                Flag = True
            elif(Kn[j] in value):
                Flag = False
                break

        if(Flag == True):
            print(i)
            break

N,K = (int(x) for x in input().split())
price(N,K)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():

    n, k = input_int_list()
    D = input_int_list()

    # N < 10000のため、嫌いな数字にかかわらず、
    # N <= ans < 100000の範囲に答えは収まる。
    # 計算量はO(n) (max_n = 5 * 10**4)

    for i in range(n, 100000):
        flag = True
        for j in str(i):
            if int(j) in D:
                flag = False
            if not flag:
                break
        if flag:
            print(i)
            return

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,k = I()
d = l()
use = [i for i in range(11) if i not in d ]
a = True
price = n

while a:
    cnt = 0
    for i in str(price):
        a = len(str(price))
        if int(i) not in d:
            cnt += 1
        else:
            cnt = inf
        if a == cnt:
            print(price)
            sys.exit()
    price += 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = set(input())
for i in range(n, 10**5):
  if set(str(i)) & D == set():
    print(i)
    exit()

Submission status: Accepted

Solution code:
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))
d0 = D[0]

def dfs(M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(M+[d0], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(M+[d], i+1, 0)
        elif d > N[i]:
            dfs(M+[d], i+1, 1)
            break
    if d0:
        dfs([d0], 0, 1)
    else:
        dfs([D[1]], 0, 1)
dfs([], 0, 0)

Submission status: Accepted

Solution code:
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))

def dfs(N, M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(N, M + [D[0]], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(N, M+[d], i+1, 0)
        elif d > N[i]:
            dfs(N, M+[d], i+1, 1)
            break
    if D[0] == 0:
        dfs(N, [D[1], D[0]], 1, 1)
    else:
        dfs(N, [D[0], D[0]], 1, 1)

dfs(N, [], 0, 0)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ds = [d for d in input().split()]
while any(c in ds for c in str(n)): n += 1
print(n)

Submission status: Accepted

Solution code:
import itertools

n,k=map(int,input().split())
d=list(input())
x=[]
ans=float('inf')

for i in range(10):
  if str(i) not in d:
    x.append(str(i))
    
for i in range(1,6):
  for lst in itertools.product(x,repeat=i):
    if int(''.join(lst))>=n:
      ans=min(ans,int(''.join(lst)))
      

print(ans)

Submission status: Accepted

Solution code:
def check(n, D):
    N = []
    while n != 0:
        N.append(n % 10)
        n //= 10
    for d in D:
        if d in N:
            return False
    return True

if __name__ == '__main__':
    n, k = [int(x) for x in input().split(' ')]
    D = [int(x) for x in input().split(' ')]
    res = n
    while True:
        if check(res, D):
            break
        else:
            res += 1
    print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(input().split())
#n = 1000
flag = True
while flag:
    flag2 = True
    for si in str(n):
        if si in d:
            n += 1
            flag2 = False
            break
    if flag2:
        break
    else:
        flag = True
            
print(n)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
*D,=input().split()
ok=1
while ok:
    ans=list(str(N))
    ok=0
    for a in ans:
        if a in D:
            ok=1
    N+=1
print(''.join(ans))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools, heapq
ans = []
heapq.heapify(ans)
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        heapq.heappush(ans, s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            heapq.heappush(ans, s)
    print(heapq.heappop(ans))
    
else:
    print(heapq.heappop(ans))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools
ans = []
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        ans.append(s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            ans.append(s)
    print(min(ans))
    
else:
  print(min(ans))

Submission status: Accepted

Solution code:
import sys
from itertools import product
def input(): return sys.stdin.readline().strip()

def main():
    """
    itertools.productを使うと高速なようなので写経
    参考：https://atcoder.jp/contests/abc042/submissions/16188969
    """
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    l = len(str(N))
    if int(str(ok[-1]) * l) < N:
        if ok[0] == 0:
            print(ok[1] * 10 ** l)
        else:
            print(str(ok[0]) * (l + 1))
    else:
        for x in product(ok, repeat=l):
            x = int("".join(map(str, x)))
            if x >= N:
                print(x)
                return



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    while True:
        check = True
        for c in str(N):
            if int(c) in D:
                check = False
        if check:
            print(N)
            return
        N += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = str(n)
while not all([c not in D for c in ans]) and int(ans) >= n:
    ans = str(int(ans) + 1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for x in dislike_nums:
    dislikes[x] = True

for n in range(N, N * 10):
    found = False
    for x in str(n):
        if dislikes[int(x)]:
            found = True
            break
    if not found:
        break
print(n)

Submission status: Accepted

Solution code:
import sys

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


while True:
  for x in [int(n) for n in str(N)]:
    if x in D:
      break
  else:
    print(N)
    sys.exit()
  N+=1

Submission status: Accepted

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

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

while True:
    tmp = set(str(N))
    b = True
    for x in tmp:
        if int(x) in D:
            b = False
            break 
    if b == True:
        break
    else:
        N += 1

print(N)

Submission status: Accepted

Solution code:
def minN(N:int, usable:list, restrict=True):
    usable.sort()
    keta = False
    if restrict:
        for i in usable:
            if i >= N:
                return str(i)
        # 桁が増える
        return '1'+str(usable[0])
    else:
        return str(usable[0])

def rote(N:list, D:set, d:set):
    ans = []
    flag = True
    lenNstr = len(N)
    for i, n in enumerate(N):
        n = int(n)
        keta = 10**(len(N) - i - 1)
        if flag:
            if n in D:
                ans.append(int(minN(n, d)) * keta)
                flag = False
            else:
                ans.append(keta * n)
        else:
            ans.append(keta * min(d))
    return sum(ans)

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = list(numset.difference(D))
    d.sort()
    for _ in range(10):
        Nstr = list(str(N))
        ans = rote(Nstr, D, d)
        N = ans    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = numset.difference(D)

    for n in range(N, pow(10, 6) + 10):
        check = set(list(str(n)))
        ngflag = False
        for i in check:
            if int(i) in D:
                ngflag = True
                break
        if not ngflag:
            break
    print(n)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
i3=lambda : map(int,input().split())

N,K=i3()
*D,=i3()

D=set(D)

for i in range(N,10**5):
    ans=1
    for s in str(i):
        if int(s) in D:
            ans=0
            break
    if ans : break
print(i)

Submission status: Accepted

Solution code:
n,k=map(int,input().split());a=set(input().split())
while True:
  if not set(str(n))&a: print(n);break
  n+=1

Submission status: Accepted

Solution code:
n,k = input().split()
hate = list(input().split())
exi = True
t = True

while True:
    for c in hate:
        t = True
        if c in list(n):
            t = False
            break
    if t:
        print(n)
        break

    intN = int(n) + 1
    n = str(intN)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
from itertools import count
for ans in count(n,1):
    for c in str(ans):
        if int(c) in D:
            break
    else:
        print(ans)
        break

Submission status: Accepted

Solution code:
def dfs(i,num_str):
    global ans_list
    if i==len(str(n)):
        ans_list.append(int(num_str))
        if len(num_list)==1:
            ans_list.append(int(num_list[0]+num_str))
        else:
            if num_list[0]=='0':
                ans_list.append(int(num_list[1]+num_str))
            else:    
                ans_list.append(int(num_list[0]+num_str))
        return
    else:
        for j in num_list:
            dfs(i+1,num_str+j)

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

ans_list = []
num_list = []
for i in range(10):
    if i not in d:
        num_list.append(str(i))
        
#print(num_list)

dfs(0,'')
sort_list = sorted(ans_list)
#print(sort_list[10:])

for i in sort_list:
    if n<=i:
        print(int(i))
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d = list(map(int,input().split()))
#print(d)
for i in range(n,10**5):
    count=0
    for j in range(k):
        u = str(d[j])
        if(str(i).count(u)==0):
            count+=1
    #print("count:"+str(count))
    if(count==k):
        print(i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
for v in range(n,10**5):
    for c in str(v):
        if int(c) in l:
            break
    else:
        print(v)
        exit()

Submission status: Accepted

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
c = 2
while c in D:
    c += 1
y = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        y = x
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[x]):
        for i in range(len(N)-1-x):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
while y > 0:
    s = ans[y][0]
    t = ans[y][1]
    r = ans[y]
    ans[y] = t
    ans[y-1] = str(int(ans[y-1]) + 1)
    if int(ans[y-1]) in D:
        u = int(ans[y-1])
        while u in D:
            u += 1
            ans[y-1] = str(u)
    if ans[y-1] != "10":
        y = 0
    else:
        y -= 1
        ans[y] = r
print("".join(ans))

Submission status: Accepted

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

v = n
while True:
    f = True
    for t in list(str(v)):
        if int(t) in d:
            f = False
            continue
    if f:
        print(v)
        exit(0)
    v+=1

Submission status: Accepted

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

def find_ok( x , Oks ):
    for i in Oks:
        if int(i) > int(x):
            break
    return i

def main():
    n,k = map( int , input().split() )
    Nos = set(map( int , input().split() ))
    while(1):
        x = str(n)
        set_n= set()
        for digit in x:
            set_n.add( int(digit) )
        if len(set_n & Nos) == 0:
            break
        n += 1
    print(n)



main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
x=list(range(1,100001))
y=[0]*100000
for i in range(100000):
    s=str(i)
    S=len(s)
    for j in range(S):
        if int(s[j]) in d:
            y[i-1]=1
            break
for i in range(100000):
    if i>=n-1:
        if y[i]==0:
            print(i+1)
            break

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N, 10**6+1):
  l = [j for j in str(i)]
  flag = True
  for n in l:
    if int(n) in s:
      flag = False
      break
  if flag:
    ans = i
    break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

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


for i in range(n,pow(10,5)):
    a=set()
    v=str(i)
    for j in range(len(v)):
        a.add(int(v[j]))

    if a.isdisjoint(d):
        print(i)
        exit()

Submission status: Accepted

Solution code:
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
import datetime
# import webbrowser

# f = open("input.txt", 'r')
# g = open("output.txt", 'w')
# n, m = map(int, f.readline().split())

n, k = map(int, input().split())
dislike = list(map(int, input().split()))
while True:
    for i in str(n):
        if int(i) not in dislike:
            continue
        else:
            break
    else:
        break
    n += 1
print(n)

Submission status: Accepted

Solution code:
def dfs(A: list):
    if len(A) > nn:
        return
    if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
        ans[0] = x
        return

    for v in d:
        if v == "0" and len(A) == 0:
            next
        A.append(v)
        dfs(A)
        A.pop()


n, k = map(int, input().split())
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
nn = len(str(n))+1
ans = [10**7]
dfs([])
print(ans[0])

Submission status: Accepted

Solution code:
def dfs(A: list):
    if len(A) > len(str(n))+1:
        return
    if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
        ans[0] = x
        return

    for v in d:
        if v == "0" and len(A) == 0:
            next
        A.append(v)
        dfs(A)
        A.pop()


n, k = map(int, input().split())
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
ans = [10**10]
dfs([])
print(ans[0])

Submission status: Accepted

Solution code:
import sys


def check(pay, like):
    str_pay = str(pay)
    like = ''.join(like)
    for p in str_pay:
        for lk in like:
            if p == lk:
                return False

    return True

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

D = []
D = list(map(int, input().split()))
str_D = []

for s in D:
    str_D.append(str(s))

pay = N

while True:
    if check(pay, str_D):
        print(pay)
        sys.exit()
    pay += 1

Submission status: Accepted

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


while True:
    
    for j in str(n):
        
        if j in a:
            break
    else:
        break
    n += 1        
    
print(n)

Submission status: Accepted

Solution code:
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) if u < n else u

print dfs(0,n,letters)

Submission status: Accepted

Solution code:
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

Submission status: Accepted

Solution code:
import itertools

def main():
	N, K = [int(n) for n in input().split(" ")]
	D = [1] * 10
	for d in input().split(" "):
		D[int(d)] = 0
	L = [str(i) for i, v in enumerate(D) if v == 1]

	digit = len(str(N))
	cand = []
	for n in list(itertools.product(L, repeat=digit)):
		p = int("".join(list(n)))
		if p >= N:
			cand.append(p)
	if len(cand):
		print(min(cand))
	else:
		if L[0] == "0":
			print(str(L[1]) + "0" * digit)
		else:
			print(str(L[0]) * (digit + 1))


main()

Submission status: Accepted

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

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

def total_to_digits(total):
    return map(int, list(str(total)))

def find_lowest_denomination(total, d):
    res = None
    for i in range(total, 99999):
        digits = list(total_to_digits(i))
        if not (set(digits) & set(d)):
            print(i)
            return


find_lowest_denomination(total, d)

Submission status: Accepted

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

for payment in range(N, 10*N+1):
    if all(char not in D for char in str(payment)):
        print(payment)
        break

Submission status: Accepted

Solution code:
#
# abc042 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)


def resolve():
    N, K = map(int, input().split())
    D = list(input().split())

    for i in range(N, 10*N+1):
        for d in D:
            if str(i).count(d) != 0:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
#
# abc042 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)


def resolve():
    N, K = map(int, input().split())
    D = list(input().split())

    for i in range(100000):
        if i < N:
            continue
        for d in D:
            if str(i).count(d) != 0:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
S = set(input().split())
while True:
    L = list(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())
arr = list(map(int, input().split()))

inf = float('inf')
min_cost = inf
for amount in range(n, 100000):
    for i, e in enumerate(arr):
        if str(e) in str(amount):
            break
        if i == len(arr)-1:
            min_cost = min(min_cost, amount)

print(min_cost)

Submission status: Accepted

Solution code:
'''
Created on 2020/08/25

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,K=map(int,pin().split())
  D=list(map(int,pin().split()))
#   l=[0,1,2,3,4,5,6,7,8,9]
#   for i in D:
#     l.remove(i)
  j=N
  while True:
    for k in str(j):
      if int(k) in D:
        break
    else:
      print(j)
      break
    j+=1
  return 
main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = set(map(int, input().split()))
while 1:
  B = set(map(int, list(str(N))))
  if len(A & B) == 0:
    print(N)
    break
  N += 1

Submission status: Accepted

Solution code:
N,K,*dd = map(int, open(0).read().split())

valid = [1] * 10
for d in dd:
    valid[d] = 0
digits = [i for i,v in enumerate(valid) if v]
num_digit = len(str(N))

from itertools import product
from sys import exit
for ans_digit in [num_digit, num_digit+1]:
    for x in product(digits, repeat=ans_digit):
        x = int(''.join(map(str, x)))
        if x >= N:
            print(x)
            exit()

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement
n, k = map(int, input().split())
d = [int(x) for x in input().split()]
dd = set(list(range(10))) - set(d)

x = str(n)
lst = []
dd = list(dd)
dd.sort()
sel = []
for i in dd:
    if int(x[0]) <= i and len(sel) < 3: sel.append(i*10**(len(x)-1))
if len(sel) < 2:
    if len(dd) == 1:
        sel.append((dd[0]*10 + dd[0])* 10 ** (len(x)-1))
    else:
        if dd[0] != 0:
            sel.append((dd[0]*10 + dd[0])* 10 ** (len(x)-1))
        else:
            sel.append((dd[1]*10 + dd[0])* 10 ** (len(x)-1))
for j in sel:
    for l in combinations_with_replacement(dd, len(x)-1):
        cnt = j
        for i in range(len(x)-1):
            cnt += 10 ** (len(x)-i-2) * l[i]
        if cnt >= n: lst.append(cnt)
print(min(lst))

Submission status: Accepted

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

while True:
    s = str(n)
    flag = True
    for c in s:
        if c in d:
            flag = False
    
    if flag:
        print(n)
        break

    n += 1

Submission status: Accepted

Solution code:
nk = list(map(lambda x: int(x), input().split(" ")))
n = nk[0]
k = nk[1]

ds = input().split(" ")

res = n
while True:
    is_ok = [str(res).find(d) == -1 for d in ds]
    if all(is_ok):
        break
    else:
        res = res + 1

print(res)

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,K=MAP()
L=list(input().split())
L=set(L)
for i in range(N,100000):
  if set(str(i))&L==set():
    print(i)
    exit()

Submission status: Accepted

Solution code:
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = set(LI())
# 最小金額から条件を満たすまで増やしていく
while True:
    if all(int(j) not in d for j in str(n)):  # 全ての桁の数字が d に属さない
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = set(LI())
# 最小金額から条件を満たすまで増やしていく
while True:
    if all([int(j) not in d for j in str(n)]):  # 全ての桁の数字が d に属さない
        print(n)
        exit()
    n += 1

Submission status: Accepted

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

can_use = []
for i in range(10):
    if (i in D):
        continue
    else:
        can_use.append(i)


while True:
    str_N = str(N)
    flag = True
    for i in range(len(str_N)):
        if int(str_N[i]) in D:
            N += 1
            flag = False
            break
        else:
            continue
    if flag:
        break

print(N)

Submission status: Accepted

Solution code:
N,K = (int(T) for T in input().split())
D = input().split()
for TN in range(N,100000):
    StrN = str(TN)
    Flag = True
    for TS in StrN:
        if TS in D:
            Flag = False
            break
    if Flag:
        print(TN)
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
digit = []
def check(n):
	global digit
	while n:
		rem  = n%10
		for i in digit:
			if i==rem:
				return False
		n = n//10
	return True
def main():
	global digit
	n , k = map(int , input().split())
	digit = list(map(int , input().split()))
	ans = n
	while (check(n))==False:
		n = n+1
	print(n)

if __name__ =="__main__":
	main()

Submission status: Accepted

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

while(True):
    x = n
    while(x):
        if x%10 in d:
            break
        x//=10
    else:
        print(n)
        quit(0)
    n += 1