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: Wrong Answer

Solution code:
N, K = map(int, input().split())
not_use = list(map(int, input().split())) # 使用不可な数字


def check(num):
    str_num = str(num)
    for s in str_num:
        if(int(s) in not_use):
            return False
    print(str_num)
    return True

if __name__ == '__main__':
    while N < 10000:
        flag = check(N)
        if(flag):
            break
        else:
            N += 1

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
not_use = list(map(int, input().split())) # 使用不可な数字


def check(num):
    str_num = str(num)
    for s in str_num:
        if(int(s) in not_use):
            return False
    print(str_num)
    return True

if __name__ == '__main__':
    while N < 10000:
        if(N == 9999):
            print(9999)
            break
        flag = check(N)
        if(flag):
            break
        else:
            N += 1

Submission status: Wrong Answer

Solution code:
import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = sorted(set(range(10)) - set(Bad))
NotZero = sorted(set(OK) - set([0]))

if str(OK[-1]) < S[0]:
    print(str(NotZero[0]) + str(OK[0]) * len(S))
    sys.exit()

count = [0] * 10
for c in str(S):
    count[ord(c) - ord('0')] += 1
greater = 0
ans = []


def can(i, d):
    c = str(d)
    if i == 0 and d == 0 and len(S) > 1:
        return 0
    if not greater and c < S[i]:
        return 0
    if c > S[i]:
        return 1
    for b in range(10):
        if count[b] > 0 and b > OK[-1]:
            return 0
    return 1

for i in range(len(S)):
    count[ord(S[i]) - ord('0')] -= 1
    for d in OK:
        if can(i, d):
            if str(d) > S[i]:
                greater = 1
            ans.append(d)
            break

print("".join(str(a) for a in ans))

Submission status: Wrong Answer

Solution code:
import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = [chr(ord('0') + i) for i in range(10) if i not in Bad]
NotZero = sorted(set(OK) - set(['0']))
ans = []

if OK[-1] < S[0]:
    print(NotZero[0] + OK[0] * len(S))
    sys.exit()
greater = 0
for i in range(len(S)):
    for d in OK:
        if i == 0 and d == '0' and len(S) > 1:
            continue
        if not greater and d < S[i]:
            continue
        if d > S[i]:
            greater = 1
        ans.append(d)
        break

print("".join(str(a) for a in ans))

Submission status: Wrong Answer

Solution code:
import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = [chr(ord('0') + i) for i in range(10) if i not in Bad]
ans = []

if OK[-1] < S[0]:
    for d in OK:
        if d > '0':
            ans.append(d)
            break
    for i in range(len(S)):
        ans.append(OK[0])
    print("".join(ans))
    sys.exit()

greater = 0
for i in range(len(S)):
    for d in OK:
        if i == 0 and d == '0' and len(S) > 1:
            continue
        if not greater and d < S[i]:
            continue
        if d > S[i]:
            greater = 1
        ans.append(d)
        break

print("".join(str(a) for a in ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
import itertools
ini = int(input().split(" ")[0])
try:
    negaset = [int(x) for x in input().split(" ")]
except :
    print (ini)
    exit()
okset = sorted([str(i) for i in range (10) if i not in negaset]) 
#print(ini,okset)

for p in itertools.product(okset,repeat = 5):
    stp = int("".join(p))
    if stp >= ini:
        print(stp)
        break

Submission status: Wrong Answer

Solution code:
import itertools
ini = int(input().split(" ")[0])
negaset = [int(x) for x in input().split(" ")]
okset = sorted([str(i) for i in range (10) if i not in negaset]) 
#print(ini,okset)

for p in itertools.product(okset,repeat = 5):
    stp = int("".join(p))
    if stp >= ini:
        print(stp)
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

ini = input().split(" ")[0]
negaset = [int(x) for x in input().split(" ")]
okset = sorted([i for i in range (10) if i not in negaset]) 
#print(ini,okset)

result = ""
flag = False
for i in [int(j) for j in ini]:
    if flag:
        result += "0"
        continue
        
    for k in range(i ,10):
        if k in okset:
            result += str(k)
        if k == i:
            flag = True
    
print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

ini = input().split(" ")[0]
negaset = [int(x) for x in input().split(" ")]
okset = sorted([i for i in range (10) if i not in negaset]) 
#print(ini,okset)

result = ""
flag = False
for i in [int(j) for j in ini]:
    if flag:
        result += str(okset[0])
        continue
        
    for k in range(i ,10):
        if k in okset:
            result += str(k)
        if k == i:
            flag = True
    
print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

ini = input().split(" ")[0]
negaset = [int(x) for x in input().split(" ")]
okset = [i for i in range (10) if i not in negaset] 
#print(ini,okset)

result = ""
for i in [int(j) for j in ini]:
    if i in okset:
        result += str(i)
        continue
    
    for k in range(i ,10):
        if k in okset:
            result += str(k)
            continue
print(result)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
drr=map(int,input().split())
digits = list(set([0,1,2,3,4,5,6,7,8,9])-set(drr))
p = len(digits)
arr=[0]
def inc(arr,p,pos):
    if arr[pos] == p-1:
        arr[pos]=0
        if pos==len(arr)-1:
            arr.append(0)
        else:
            inc(arr,p,pos+1)
    else:
        arr[pos]+=1

def calc(arr,digits):
    sum=0
    for i in range(len(arr)):
        sum+=10**i*digits[arr[i]]
    return sum

ans=calc(arr,digits)

while(ans<n):
#    print("hoge: %d" % ans)
    inc(arr,p,0)
    ans=calc(arr,digits)

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dislike = input().split()
i = 1
while True:
    money = str(n * i)
    if len(set(money).intersection(dislike)) == 0:
        print(money)
        break
    i += 1

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dislike = list(map(str, input().split()))
i = 1
flag = True
while flag:
    money = str(n * i)
    for s in money:
        if s in dislike:
            flag = True
            break
        else:
            flag = False
    i += 1
print(money)

Submission status: Wrong Answer

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

def main():
    N, K = map(int, input().split())
    D = input().split()
    s = str(N)
    d = None
    for a, b in zip(sorted(map(int, D)), [1,2,3,4,5,6,7,8,9]):
        if a != b:
            d = str(b)
            break
    D = set(D)
    for i in range(N, 1 + int(d * (len(s) + 1))):
        if len(set(str(i)).intersection(D)) == 0:
            print(i)
            break

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def no_dislike_number(num, D):
    for digit in num:
        if int(digit) in D:
            return False
    return True
    # for dislike in D:
    #     if dislike in num:
    #         return False
    # return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

Submission status: Wrong Answer

Solution code:
#coding=UTF-8

mojir=input()
hyo=mojir.split(' ')

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

mojir=input()
hyo=mojir.split(' ')
D=[int(mono) for mono in hyo]

kouho=N

def usecheck(gaku):
    gakustr=str(gaku)
    keta=len(gakustr)
    dame=None
    for idx in range(0,keta,1):
        if gakustr[idx] in hyo:
            dame=idx
            break

    if dame == None:
        return None
    else:
        return (keta-dame)

#積極的に枝刈りを
while True:
    print(kouho)
    dameketa=usecheck(kouho)
    if dameketa == None:
        break

    kouho=(kouho//(10**(dameketa-1)) +1)*(10**(dameketa-1))

print(kouho)

Submission status: Wrong Answer

Solution code:

dislike = []
basic = ["0","1","2","3","4","5","6","7","8","9"]
like = []
N = []
ans = ""

def get_input():
    cnt = 0
    while True:
        a = input()
        yield ''.join(a)
        cnt += 1
        if cnt >= 2:
            break

if __name__ == "__main__":
    array = list(get_input())
    intN,K = array[0].split()
    payment = intN
    strN = str(intN)
    N = list(strN)
    dislike = array[1].split()
    #print(dislike)
    #print(N)
    set_like = set(basic) - set(dislike)
    like = list(set_like)
    #print(N)
    for i in range(0,len(N)):
        for j in like:
            #print("j is {0}".format(j))
            if j >= N[i]:
                #print("j:{0},N[i]:{1}".format(j,N[i]))
                ans+=j
                break

    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
N, K = map(int, raw_input().split(" "))
D = map(int, raw_input().split(" "))
nums = range(0,10)
#好きな数字を昇順のリストに整理
like = list(set(nums).difference(set(D)))
like.sort()
#数字を上から1文字づつ処理
grade = len(str(N))-1
ans = 0
flag = False #上の桁で嫌いな数字があるか
for i in str(N):
    if int(i) == 9 and 9 not in like and not flag:
        ans += 10**(grade+1)
        flag = True
    elif int(i) not in like and not flag:
        for j in like:
            if j > int(i):
                ans += j*10**(grade)
                flag = True
                break
    elif flag:
        ans += like[0]*10**(grade)
    grade -= 1
if ans < N:
    ans = N
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
N, K = map(int, raw_input().split(" "))
D = map(int, raw_input().split(" "))
nums = range(0,10)
#好きな数字を昇順のリストに整理
like = list(set(nums).difference(set(D)))
like.sort()
print like
#数字を上から1文字づつ処理
grade = len(str(N))-1
ans = 0
flag = False #上の桁で嫌いな数字があるか
for i in str(N):
    if int(i) == 9 and 9 not in like and not flag:
        ans += 10**(grade+1)
        flag = True
    elif int(i) not in like and not flag:
        for j in like:
            if j > int(i):
                ans += j*10**(grade)
                flag = True
                break
    elif flag:
        ans += like[0]*10**(grade)
    grade -= 1
if ans < N:
    ans = N
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
N, K = map(int, raw_input().split(" "))
D = map(int, raw_input().split(" "))
nums = range(0,10)
#好きな数字を昇順のリストに整理
like = list(set(nums).difference(set(D)))
like.sort()
#数字を上から1文字づつ処理
grade = len(str(N))-1
ans = 0
flag = False #上の桁で嫌いな数字があるか
for i in str(N):
    if int(i) == 9 and not flag:
        ans += 10**(grade+1)
        flag = True
    elif int(i) not in like and not flag:
        for j in like:
            if j > int(i):
                ans += j*10**(grade)
                flag = True
                break
    elif flag:
        ans += like[0]*10**(grade)
    grade -= 1
if ans < N:
    ans = N
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
N, K = map(int, raw_input().split(" "))
D = map(int, raw_input().split(" "))
nums = range(0,10)
#好きな数字を昇順のリストに整理
like = list(set(nums).difference(set(D)))
like.sort()
#数字を上から1文字づつ処理
grade = len(str(N))-1
ans = 0
flag = False #上の桁で嫌いな数字があるか
for i in str(N):
    if int(i) not in like and not flag:
        for j in like:
            if j > int(i):
                ans += j*10**(grade)
                flag = True
                break
    elif flag:
        ans += like[0]*10**(grade)
    grade -= 1
if ans < N:
    ans = N
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
N, K = map(int, raw_input().split(" "))
D = map(int, raw_input().split(" "))
nums = range(0,10)
#好きな数字を昇順のリストに整理
like = list(set(nums).difference(set(D)))
like.sort()
#数字を上から1文字づつ処理
grade = len(str(N))-1
ans = 0
flag = False #上の桁で嫌いな数字があるか
for i in str(N):
    if int(i) not in like:
        for j in like:
            if j > int(i):
                ans += j*10**(grade)
                flag = True
                break
    elif flag:
        ans += int(i)*10**(grade)
    grade -= 1
if ans < N:
    ans = N
print ans

Submission status: Wrong Answer

Solution code:
catch = input()
catch = catch.split(" ")

N = list(catch[0])
K = int(catch[1])
OF = 0

for i in range(len(N)):
    N[i] = int(N[i])

kirai = []

catch = input()
catch = catch.split(" ")


for i in catch:
    kirai.append(int(i))

kirai.sort()

for i in range(len(N)-1, 0, -1):

    while True:

        if N[i] >9:
            N[i-1] +=1
            N[i] = N[i]%10
        elif N[i] not in kirai:
            break
        elif N[i] == 9:
            N[i] = 0
            N[i-1] +=1
        else:
            N[i] +=1

while True:
    if N[0] >9:
        OF +=1
        N[0] = N[i]%10
    elif N[0] not in kirai:
        break
    elif N[0] == 9:
        N[0] = 0
        OF +=1
    else:
        N[0] +=1

if OF == 0:
    for i in range(len(N)):
        print(N[i], end = "")
else:
    print(OF, end = "")
    for i in range(len(N)):
        print(N[i], end = "")
print()

Submission status: Wrong Answer

Solution code:
catch = input()
catch = catch.split(" ")

N = list(catch[0])
K = int(catch[1])
OF = 0

for i in range(len(N)):
    N[i] = int(N[i])

kirai = []

catch = input()
catch = catch.split(" ")


for i in catch:
    kirai.append(int(i))

kirai.sort()

for i in range(len(N)-1, 0, -1):

    while True:

        if N[i] >9:
            N[i-1] +=1
            N[i] = N[i]%10
        elif N[i] not in kirai:
            break
        elif N[i] == 9:
            N[i] = 0
            N[i-1] +=1
        else:
            N[i] +=1

if N[0] >9:
    OF +=1
    N[0] == N[0]%10

while True:
    if N[0] >9:
        OF +=1
        N[0] = N[i]%10
    elif N[0] not in kirai:
        break
    elif N[0] == 9:
        N[0] = 0
        OF +=1
    else:
        N[0] +=1

if OF == 0:
    for i in range(len(N)):
        print(N[i], end = "")
else:
    print(OF, end = "")
    for i in range(len(N)):
        print(N[i], end = "")
print()

Submission status: Wrong Answer

Solution code:
import itertools
N, K = map(int, raw_input().split())
d = map(int, raw_input().split())
d = set(d)
ok = set(range(10)) - d
ok = list(ok)
ok = [str(i) for i in ok]
i = len(str(N))
while True:
    for ele in itertools.product(ok, repeat=i):
        if int("".join(list(ele))) >= N:
            print "".join(list(ele))
            exit()
    i += 1

Submission status: Wrong Answer

Solution code:
import itertools
N, K = map(int, raw_input().split())
d = map(int, raw_input().split())
d = set(d)
ok = set(range(10)) - d
ok = list(ok)
ok = [str(i) for i in ok]
i = len(str(N))
while True:
    for ele in itertools.product(ok, repeat=i):
        if int("".join(list(ele))) > N:
            print "".join(list(ele))
            exit()
    i += 1

Submission status: Wrong Answer

Solution code:
catch = input()
catch = catch.split(" ")

N = list(catch[0])
K = int(catch[1])
OF = 0

for i in range(len(N)):
    N[i] = int(N[i])

kirai = []

catch = input()
catch = catch.split(" ")


for i in catch:
    kirai.append(int(i))

kirai.sort()


for i in range(len(N)-1, 0, -1):

    if N[i] >9:
        N[i-1] +=1
        N[i] == a%10

    while True:
        if N[i] not in kirai:
            break
        elif N[i] == 9:
            N[i] == 0
            n[i-1] +=1
        else:
            N[i] +=1


if N[0] >9:
    OF +=1
    N[0] == a%10

while True:
    if N[0] not in kirai:
        break
    elif N[0] == 9:
        N[0] == 0
        OF +=1
    else:
        N[0] +=1

if OF == 0:
    for i in range(len(N)):
        print(N[i], end = "")
else:
    print(OF, end = "")
    for i in range(len(N)):
        print(N[i], end = "")
print()

Submission status: Wrong Answer

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

D = map(int, raw_input().split())

for i in range(N, 10001):

  flag = 0

  for j in D:
    if str(j) in str(i):
      flag = 1
      break

  if flag == 0:
    print i
    exit()

Submission status: Wrong Answer

Solution code:
n, _ = input().split(' ')
o = set([d for d in range(10)])
d = set([int(t) for t in input().split(' ')])
o = list(o.difference(d))
o.sort()
ans = []
for t in n:
    t = int(t)
    for tt in o:
        if tt >= t or (len(ans) != 0 and ans[0] > int(n[0])):
            ans.append(tt)
            break
    else:
        ans.append(o[0])

if int(''.join(map(str,ans))) < int(n):
    ans.insert(0, o[0] if o[0] != 0 else o[1])

print(''.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
def no_dislike_number(num, D):
    for dislike in D:
        if dislike in num:
            return False
    return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
for num in range(N, MAX+1):
    if no_dislike_number(str(num), D):
        print(num)
        break

Submission status: Wrong Answer

Solution code:
cond = [int(n) for n in input().split(" ")]
exclude = {n for n in range(10)}
answer = ""
mo = {str(n) for n in input().split(" ")}
exclude = exclude - mo
for n in range(cond[0],10000):
    for m in [n for n in str(n)]:
        if m in mo:
            break
    else:
        print(n)
        break

Submission status: Wrong Answer

Solution code:
n, _ = input().split(' ')
o = set([d for d in range(10)])
d = set([int(t) for t in input().split(' ')])
o = list(o.difference(d))
o.sort()
ans = []
for t in n:
    t = int(t)
    for tt in o:
        if tt >= t:
            ans.append(tt)
            break
    else:
        ans.append(o[0])

if int(''.join(map(str,ans))) < int(n):
    ans.insert(0, o[0] if o[0] != 0 else o[1])

print(''.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
def check_no_dislike_number(num, D):
    num_str = str(num)
    for dislike in D:
        if dislike in num_str:
            return False
    return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
for num in range(N, MAX):
    if check_no_dislike_number(num, D):
        print(num)
        break

Submission status: Wrong Answer

Solution code:
n, _ = input().split(' ')
o = set([d for d in range(10)])
d = set([int(t) for t in input().split(' ')])
o = list(o.difference(d))
o.sort()
for t in n:
    t = int(t)
    for tt in o:
        if tt >= t:
            print(tt, end='')
            break
print()

Submission status: Wrong Answer

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

ans = n
f = 0
while True:
    ansstr = list(str(ans))
    l = len(ansstr)
    for i in range(l):
        if ansstr[i] in d:
            break
        else:
            f = 1
            break

    if f:
        break

    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, raw_input().split())
D = "".join(raw_input().strip().split())
for i in xrange(N, 10000+1):
    flag = True
    for c in str(i):
        if c in D:
            flag = False
    if flag:
        print i
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, raw_input().split())
D = "".join(raw_input().strip().split())
for i in xrange(N, 10000+1):
    flag = True
    for c in str(i):
        if c in D:
            flag = False
    if flag:
        print i
        __import__('sys').exit(1)

Submission status: Time Limit Exceeded

Solution code:
n,k = input().split()
d = list(map(int,input().split()))
num = [i for i in range(10)]
poss = list(set(d) ^ set(num))
an = int(n)
while True:
    sum = 0
    for p in poss:
        sum += n.count(str(p))
    if sum ==len(n):
        break
    else:
        an +=1
print(an)

Submission status: Time Limit Exceeded

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

for i in range(n, 10**5):
    tmp = i
    last = tmp % 10
    while i > 0 and last not in d:
        tmp //= 10
        last = tmp % 10
    if tmp == 0:
        print(i)
        break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)

ok = True

while True:
    s = list(str(n))
    for _d in d:
        if str(_d) in s:
            ok = False
            break
    
    if ok:
        print(n)
        exit()
    else:
        n += 1

Submission status: Time Limit Exceeded

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
n=l[0]
n_list=list(int(j) for j in str(n))  
while True:
    n_set=set(n_list)
    if n_set<=d_bar:
        print(n)
    else:
        n=n+1

Submission status: Time Limit Exceeded

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
N=l[0]
K=l[1]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(N)]
dig1=''
dig2=0
for i in range(len(n)):
    for j in range(len(d_bar)):
        p=dig1+str(d_bar[j])
        if int(p)>l[0]:
            dig2=dig2*K**i+int(dig1)
            break
        dig1=p
        
dig2=dig2+1
r=dig2
q=dig2
R=[]
while q!=0 or q!=1:
    q=q//K
    r=q%K
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))

Submission status: Time Limit Exceeded

Solution code:
l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=''
    dig2=0
    for j in range(l[1]):
        p=dig1.join(str(d_bar[j]))
        if int(p)>l[0]:
          dig2=dig2+int(dig1)*l[1]**(l[0]-i)
          break
        dig1=p     
dig2=dig2+1
r=int(dig1)
q=int(dig1)
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))

Submission status: Time Limit Exceeded

Solution code:
l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=''
    dig2=0
    for j in range(l[1]):
        p=dig1.join(str(d_bar[j]))
        if int(p)>l[0]:
          break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(l[0]-i)
dig2=dig2+1
r=int(dig1)
q=int(dig1)
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))

Submission status: Time Limit Exceeded

Solution code:
l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=0
    dig2=0
    for j in range(l[1]):
        p=dig1+d_bar[j]*10**(l[0]-i)
        if p>l[0]:
            break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(l[0]-i)
dig2=dig2+1
r=dig1
q=dig1
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=0
for t in range(len(R)):
    s=s+R[t]*10**(t)
print(s)

Submission status: Time Limit Exceeded

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

L=[]
for i in range(0, 10):
    if i not in D:
        L.append("i")    

i = N
while True:
    if set(list(str((i)))) <= set(L):
        print(i)
        break
    i += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
#from collections import deque

N, K = mi()
D = li()

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

if r[0]==0:
    #que = deque(r[1:])
    que = r[1:]
else:
    #que = deque(r)
    que = r

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        que.append(new)
    if que[-1] >= 10**6:
        break
    i += 1

ind = bisect.bisect_left(que, N)
#print(que)
#print(ind)
print(que[ind])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
d = list(input().split())
ans = n
flag = True
while flag:
    for i in d:
        if flag :break
        if i in str(ans):
            x = len(str(ans)) - str(ans).index(i) - 1
            ans += 10**x
            flag = False

print(ans)

Submission status: Time Limit Exceeded

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

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

ans = n
while (1):

    c = True
    b = n
    while (b != 0):
        b = b // 10
        d = b % 10

        if d in a:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b=map(int,input().split())
l=list(map(int,input().split()))
list_a= [int(s) for s in l]
while True:
  for c in l:
    if c in list_a:
      a+=1
      continue
    else:
      print(a)
      break

Submission status: Time Limit Exceeded

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}
Ds = set(D)
diff = num^Ds
ans = N
while True:
    strN = str(N)
    flag = False
    for i in strN:
        if int(i) not in diff:
            flag = True
    if flag:
        ans += 1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import string
n,k =[int(i) for i in input().split()]
not_use=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in not_use]

def check(n):
    for i in str(n):
        if(int(i) in not_use):
            return False
    return True


x=n-1
while True:
    x+=1
    if(check(x)==True):
        print(x)

Submission status: Time Limit Exceeded

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

ok = False
found = False
while not ok:
    money_digits = [int(mon) for mon in str(money)]

    for digit in money_digits:
        for dis_digit in dislike_digits:
            if digit == dis_digit:
                found = True
                break
        if found:
            money += 1
            break

    if not found:
        ok = True

print(money)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 1
while 1:
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        i = 0
    i += 1
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
    if i == a + 1:
        break
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = (n[0] % 10000) // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    f = n[0] // 10000
    
    if np.any(d == f):
        n[0] = f * 10000
    elif np.any(d == a):
        n[0] = f * 10000 + (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = a * 1000 + (b + 1) * 100
    elif np.any(d == c):
        n[0] = a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = n[0] // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    
    if np.any(d == a):
        n[0] = (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = a * 1000 + b * 100
    elif np.any(d == c):
        n[0] = a * 1000 + b * 100 + c * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+10**c
                t=1
                break
    if t==0:
        break
print(n)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

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

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


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


print(dfs(''))