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:
import math

def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec
def floor(n, i):
    dec = 10 ** i
    return n // dec * dec + dec

(n, k) = list(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)
for i in range(1, len(str(n)) + 1):
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = floor(n, i)
        n += int(str(l[0]) * i)
        
print(n)

Submission status: Wrong Answer

Solution code:
import math

def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec
def floor(n, i):
    dec = 10 ** i
    return n // dec * dec + dec

(n, k) = list(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)
for i in range(1, len(str(n)) + 1):
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    print(nown)
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            print(str(j) + str(l[0]) * (i - 1))
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = floor(n, i)
        n += int(str(l[0]) * i)
        
print(n)

Submission status: Wrong Answer

Solution code:
import sys
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
L=[0]*10
for i in range(K):
    L[D[i]]=1
for i in range(N,10000):
    x=str(i)
    flag=True
    for k in range(len(x)):
        y=int(x[k])
        if L[y]==1:
            flag=False
    if flag:
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
D=list(map(int,input().split()))
a=N
b=0
for i in range(N,10001):
    for j in range(len(D)):
        if str(D[j]) in str(i):
            break  
    else:
        
        break
print(i)

Submission status: Wrong Answer

Solution code:
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


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

d = [int(i) for i in input().split()]

for i in range(10001):
    if i >= N :
        if dig_check(i,d):
            print(i)
            break

Submission status: Wrong Answer

Solution code:
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


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

d = [int(i) for i in input().split()]

for i in range(10001):
    if i > N :
        if dig_check(i,d):
            print(i)
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(10*n+2):
  if i >= n:
    s = str(i)
    for j in range(len(s)):
      if int(s[j]) in d:
        break
      else:
        print(i)

Submission status: Wrong Answer

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

for i in range(N,10000):
    match = False
    for s in str(i):
        if s in D:
            match = True
            break
    if not match:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import random
import time

numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
count = random.randint(1, 9)
dk, i = [], 0
while i < count:
    m = random.choice(numbers)
    if m not in dk:
        dk.append(m)
        i += 1
    else:
        continue

start = time.clock()
number_input = random.randint(10, 10000)
number_result = number_input
while True:
    string_middle = str(number_result)
    judge = 0
    for each in string_middle:
        if each in dk:
            judge = 1
            break
        else:
             continue
    if judge == 1:
        number_result += 1
    else:
        break
print('%d %d'%(number_input, count))
print(dk)
print('%d'%number_result)

Submission status: Wrong Answer

Solution code:
import sys
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,10000):
  s=str(i)
  for j in d:
    if(j in s):
      break
  else:
    print(i)
    sys.exit()

Submission status: Wrong Answer

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

D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

mv = str(D_bar[0])
ld = 10 - int(K)
l = len(N)
index = -1
for i in range(l):
	if int(N[i]) in D:
		index = i
		break

if index == (-1):
	print(n)
	exit(0)

for i in range(index,-1,-1):
	p = bisect.bisect_left(D_bar,int(N[i]))
	if p == ld:
		N[i] = mv
		if i == 0:
			m = str(D_bar[0]) if D_bar[0] != 0 else str(D_bar[1])
			N[0] = mv
			N.insert(0,m)
		else:
			N[i-1] = str(int(N[i-1]) + 1)
	else:
		N[i] = str(D_bar[p])
		break

print(''.join(N))

Submission status: Wrong Answer

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

D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

mv = str(D_bar[0])
ld = 10 - int(K)
l = len(N)
index = -1
for i in range(l):
	if int(N[i]) in D:
		index = i
		break

if index == (-1):
	print(n)
	exit(0)

for i in range(index,-1,-1):
	p = bisect.bisect_left(D_bar,int(N[i]))
	if p == ld:
		N[i] = mv
		if i == 0:
			m = str(D_bar[0]) if D_bar[0] != 0 else str(D_bar[1])
			N[0] = mv
			N.insert(0,m)
	else:
		N[i] = str(D_bar[p])
		break

print(''.join(N))

Submission status: Wrong Answer

Solution code:
import bisect
N,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

ld = len(D_bar)
l = len(N)

mv = str(D_bar[0]) if D_bar[0] != 0 else str(D_bar[1])
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = mv + str(D_bar[0])*(l)
	else:
		p = bisect.bisect_left(D_bar,int(N[0]))
		if p == ld:
			p = (-1)
		ans = str(D_bar[p]) + str(D_bar[0])*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			if N[i] == '9':
				ans = N[:i-1] + mv + (str(D_bar[0])*max(0,l-i))
			else:
				p = bisect.bisect_left(D_bar,num)
				if p == ld:
					p = (-1)
				ans = N[:i] + str(D_bar[p]) + (str(D_bar[0])*max(0,l-i-1))

			break

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

ld = len(D_bar)
l = len(N)

mv = str(D_bar[0]) if D_bar != 0 else str(D_bar[1])
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = mv + str(D_bar[0])*(l)
	else:
		p = bisect.bisect_left(D_bar,int(N[0]))
		if p == ld:
			p = (-1)
		ans = str(D_bar[p]) + str(D_bar[0])*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			if N[i] == '9':
				ans = N[:i-1] + mv + (str(D_bar[0])*max(0,l-i))
			else:
				p = bisect.bisect_left(D_bar,num)
				if p == ld:
					p = (-1)
				ans = N[:i] + str(D_bar[p]) + (str(D_bar[0])*max(0,l-i-1))

			break

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

ld = len(D_bar)

l = len(N)
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = '10' + str(D_bar[0])*(l-1)
	else:
		p = bisect. bisect_left(D_bar,int(N[0]))
		if p == ld:
			p = (-1)
		ans = str(D_bar[p]) + str(D_bar[0])*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			index = i
			if N[i] == '9':
				ans = N[:i-1] + '10' + (str(D_bar[0])*max(0,l-i-1))
			else:
				p = bisect. bisect_left(D_bar,num)
				if p == ld:
					p = (-1)
				ans = N[:i] + str(D_bar[p]) + (str(D_bar[0])*max(0,l-i-1))

			break

print(ans)

Submission status: Wrong Answer

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

l = len(N)
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = '10' + '0'*(l-1)
	else:
		ans = str((int(N[0])+1)) + '0'*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			index = i
			if N[i] == '9':
				ans = N[:i-1] + '10' + ('0'*max(0,l-i-1))
			else:
				ans = N[:i] + str(num+1) + ('0'*max(0,l-i-1))

			break

print(ans)

Submission status: Wrong Answer

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

l = len(N)
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = '10' + N[1:]
	else:
		ans = str((int(N[0])+1)) + N[1:]

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			index = i
			if N[i] == '9':
				ans = N[:i-1] + '10' + ('0'*max(0,l-i+1))
			else:
				ans = N[:i] + str(num+1) + ('0'*max(0,l-i+1))

			break

print(ans)

Submission status: Wrong Answer

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


while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        print(n)
        exit()
    n+=1

Submission status: Wrong Answer

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

while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        print(n)
        exit()
    n+=1

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
can_use = set(map(str, set(range(10)) - set(map(int, raw_input().split()))))
for i in xrange(n, 10000):
    if set(str(i)) == can_use:
        print i
        exit()
print 0

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    for ii in range(n, 10**9):
        l = [int(x) for x in list(str(ii))]
        ll =[q for q in l if q in d]
        print(ii, ll)
        if len(ll) == 0:
            print(ii)
            break
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    for ii in range(10001):
        if ii >= n:
            l = [int(x) for x in list(str(ii))]
            ll =[q for q in l if q in d]
            if len(ll) == 0:
                print(ii)
                break
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    ans = []
    digit = len(str(n))
    f = False
    for _n in str(n):
        for _i in i:
            if _i == int(_n):
                ans.append(str(_i))
                break
            if _i > int(_n):
                ans.append(str(_i))
                f = True
                break
        digit-=1
        if f:
            break
    if f:
        for _ in range(digit):
            ans.append(str(min(i)))
    print(''.join(ans))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    ans = []
    digit = len(str(n))
    f = False
    for _n in str(n):
        for _i in i:
            if _i == int(_n):
                ans.append(str(_i))
                break
            if _i > int(_n):
                ans.append(str(_i))
                f = True
                break
        digit-=1
        if f:
            break
    if f:
        print(digit)
        for _ in range(digit):
            ans.append(str(min(i)))
    print(''.join(ans))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    ans = []
    digit = len(str(n))
    f = False
    for _n in str(n):
        for _i in i:
            if _i == int(_n):
                ans.append(str(_i))
                break
            if _i > int(_n):
                ans.append(str(_i))
                if 0 not in d:
                    f = True
                break
        digit-=1
        if f:
            break
    if f:
        print(int(''.join(ans)) * (10**digit))
    else:
        print(''.join(ans))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    ans = []
    digit = len(str(n))
    f = False
    for _n in str(n):
        for _i in i:
            if _i == int(_n):
                ans.append(str(_i))
                break
            if _i > int(_n):
                ans.append(str(_i))
                f = True
                break
        digit-=1
        if f:
            break
    if f:
        print(int(''.join(ans)) * (10**digit))
    else:
        print(''.join(ans))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    ans = []
    for _n in str(n):
        for _i in i:
            if _i >= int(_n):
                ans.append(str(_i))
                break
    print(''.join(ans))        
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    N, K = input().split()
    l = list(set(list('0123456789')) - set(input().split()))
    t = int(N)
    for i in itertools.product(l, repeat=len(N)):
        if int(''.join(i)) >= t:
            print(''.join(i))
            return
    for i in itertools.product(l, repeat=len(N)+1):
        if int(''.join(i)) >= t:
            print(''.join(i))
            return
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N, K = input().split()
Dx = list(map(int, input().split()))
nums = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
flg = False
ans = ""

def f(n, nums):
    for i in nums:
        if i > n:
            return str(i)
    return ''

for i in Dx:
    nums.remove(i)

if int(N[0]) in Dx:
    r = f(int(N[0]), nums)
    if r is '':
        r = f(0, nums)
        flg = True
    ans += r
else:
    ans += N[0]

for i in range(1, len(N)):
    if int(N[i]) in Dx:
        ans += str(nums[0])
    else:
        ans += N[i]
if flg:
    ans += str(nums[0])
print(ans)

Submission status: Wrong Answer

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

N, K = input().split()
Dx = list(map(int, input().split()))
nums = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
ans = ""

def f(n, nums):
    for i in nums:
        if i > n:
            return str(i)

for i in Dx:
    nums.remove(i)

if int(N[0]) in Dx:
    ans += f(int(N[0]), nums)
else:
    ans += N[0]

for i in range(1, len(N)):
    if int(N[i]) in Dx:
        ans += str(nums[0])
    else:
        ans += N[i]

print(ans)

Submission status: Wrong Answer

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

N, K = input().split()
Dx = list(map(int, input().split()))
nums = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
ans = ""
for i in Dx:
    nums.remove(i)

if int(N[0]) in Dx:
    if nums[0] is not 0:
        ans += str(nums[0])
    else:
        ans += str(nums[1])
else:
    ans += N[0]

for i in range(1, len(N)):
    if int(N[i]) in Dx:
        ans += str(nums[0])
    else:
        ans += N[i]

print(ans)

Submission status: Wrong Answer

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

cnt = 0
while str(n)[cnt:]:
    cnt += 1
    t = int(str(n)[-cnt])
    tmp = t
    while str(t % 10) in d:
        t += 1
    n += (t - tmp) * 10**(cnt - 1)
print(n)

Submission status: Wrong Answer

Solution code:

inpt = input().split(" ")

maxNum = inpt[0]

dislike = input().split(" ")
dislike = [int(a) for a in dislike]

likeArray = []

for i in range(0,10):
    if not i in dislike:
        likeArray.append(i)

ans = ""
flag = False
for c in maxNum:
    if flag :
        ans += str(min(likeArray))
    else:
        if int(c) in likeArray:
            ans += c
        elif len([a for a in likeArray if a > int(c)])>0:
            ans += str(min([a for a in likeArray if a > int(c)]))
            flag = True
        else:
            ans = str(min([a for a in likeArray if a > 0]))
            flag = True
print(ans)

Submission status: Wrong Answer

Solution code:

inpt = input().split(" ")

maxNum = inpt[0]

dislike = input().split(" ")
dislike = [int(a) for a in dislike]

likeArray = []

for i in range(0,10):
    if not i in dislike:
        likeArray.append(i)

ans = ""
for c in maxNum:
    temp = [a for a in likeArray if a >= int(c)]
    if(len(temp)) > 0:
        ans += str(min(temp))
    else:
        ans = str(min([a for a in likeArray if a > 0]))
        for i in range(0, len(maxNum)):
            ans += str(min(likeArray))
        break


print(ans)

Submission status: Wrong Answer

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

x=[]
while N!=0:
    x.append(N%10)
    N/=10
    N=int(N)



i=0
while True:    
    for k in range(8):
        if x[i] in  D:
            x[i]+=1
            if x[i]==10 and i==len(x)-1:
                x.append(1)
            x[i]%=10
        else:

            break

        if k==8:
            break

    if i==len(x)-1:
        break

    i+=1


res=""
for sx in reversed(x):
    res+=str(sx)
print(res)

Submission status: Wrong Answer

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

x=[]
while N!=0:
    x.append(N%10)
    N/=10
    N=int(N)




i=0
while True:
    for k in range(8):
        if x[i] in  D:
            x[i]+=1
            x[i]%=10
        else:
            i+=1
            break

        if k==8:
            break

    if i==len(x)-1:
        break


res=""
for sx in reversed(x):
    res+=str(sx)
print(res)

Submission status: Wrong Answer

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

x=[]
while N!=0:
    x.append(N%10)
    N/=10
    N=int(N)




i=0
while True:    
    for k in range(8):
        if x[i] in  D:
            x[i]+=1
            x[i]%=10
        else:
            i+=1
            break

        if k==8:
            break

    if i==len(x):
        break


res=""
for sx in reversed(x):
    res+=str(sx)
print(res)

Submission status: Wrong Answer

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

x=[]
while N!=0:
    x.append(N%10)
    N/=10
    N=int(N)




i=0
while True:
    print(x)
    for k in range(8):
        if x[i] in  D:
            x[i]+=1
            x[i]%=10
        else:
            i+=1
            break

        if k==8:
            break

    if i==len(x):
        break


res=""
for sx in reversed(x):
    res+=str(sx)
print(res)

Submission status: Wrong Answer

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

x=[]
while N!=0:
    x.append(N%10)
    N/=10
    N=int(N)




i=0
while True:

    for k in range(9):
        if x[i] in  D:
            x[i]+=1
        else:
            i+=1
            break

        if k==8:
            break

    if i==len(x)-1:
        break


res=""
for sx in reversed(x):
    res+=str(sx)
print(res)

Submission status: Wrong Answer

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

x=[]
while N!=0:
    x.append(N%10)
    N/=10
    N=int(N)




i=0
while True:

    for k in range(9):
        if x[i] in  D:
            x[i]+=1
        else:
            i+=1
            break

        if k==8:
            break

    if i==len(x):
        break


res=""
for sx in reversed(x):
    res+=str(sx)
print(res)

Submission status: Wrong Answer

Solution code:


mark=[0 for i in range(10)]
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())

for el in l:
	mark[el]=1

temp=str(n)
st=""

st=temp

for i in range(len(temp)):

	if int(temp[i]) in l:
		
		for j in range(9):
			if j>=int(temp[i]) and mark[j]==0:
				st=str(j)
				break
		# print st
		st=temp[:i]+st							

		while len(st)<len(temp):
			st = st+"0"
		break			


print st

Submission status: Wrong Answer

Solution code:


mark=[0 for i in range(10)]
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())

for el in l:
	mark[el]=1

temp=str(n)
st=""

st=temp

for i in range(len(temp)):

	if int(temp[i]) in l:
		
		for j in range(10):
			if j>=int(temp[i]) and mark[j]==0:
				st=str(j)
				break
		# print st
		st=temp[:i]+st							

		while len(st)<len(temp):
			st = st+"0"
		break			


print st

Submission status: Wrong Answer

Solution code:


mark=[0 for i in range(10)]
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())

for el in l:
	mark[el]=1

temp=str(n)
st=""

st=temp

for i in range(len(temp)):

	if int(temp[i]) in l:
		
		for j in range(10):
			if j>=int(temp[i]) and mark[j]==0:
				st=str(j)
		# print st
		st=temp[:i]+st							

		while len(st)<len(temp):
			st = st+"0"
		break			


print st

Submission status: Wrong Answer

Solution code:

mark=[0 for i in range(10)]
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())

for el in l:
	mark[el]=1


l.sort()
temp=(n)
st=""
while temp>0:

	d=temp%10

	for i in range(10):

		if i>=d and mark[i]==0:
			st=str(i)+st
			break
	temp=temp//10	

print st

Submission status: Wrong Answer

Solution code:
n, k = tuple(map(int, input().split(' ')))
ds_str = input().split(' ')
ds = list(map(int, ds_str))
ans = 0
m = len(str(n))
i = m-1
flag = False
mn = list(set(range(0,10)) - set(ds))[0]

while i >= 0:
    if flag == True and ans != 0:
        ans += mn * 10**i
        i -= 1
        continue
    d = n // 10**i
    if d in ds:
        n += 10**i
        flag = True
    else:
        ans += d * 10**i
        n %= 10**i
        i -= 1

print(ans)

Submission status: Wrong Answer

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

valid_nums = [i for i in range(10) if not i in D]
N = [int(n) for n in list(N)]
ans = []
is_less = False
for n in reversed(N):
    for i in range(0, 10-n):
        if n+i in valid_nums:
            ans.append(n+i)
            is_less = is_less if(i == 0) else False
            break
    else:
        is_less = True
        ans.append(valid_nums[0])

if is_less:
    valid_min = valid_nums.pop(0)
    ans.append(valid_min if(valid_min != 0) else valid_nums.pop(0))

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

Submission status: Wrong Answer

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

valid_nums = [i for i in range(10) if not i in D]
N = [int(n) for n in list(N)]
ans = []
is_large = False
for n in reversed(N):
    for i in range(0, 10-n):
        if n+i in valid_nums:
            ans.append(n+i)
            is_large = False if(i == 0) else True
            break
    else:
        is_large = False
        ans.append(valid_nums[0])

if not is_large:
    valid_min = valid_nums.pop(0)
    ans.append(valid_min if(valid_min != 0) else valid_nums.pop(0))

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

Submission status: Wrong Answer

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

valid_nums = [i for i in range(10) if not i in D]
N = [int(n) for n in list(N)]
ans = []
for n in N:
    for i in range(0, 10-n):
        if n+i in valid_nums:
            ans.append(n+i)
            break
    else:
        ans.append(valid_nums[0])

for n, a in zip(N, ans):
    if n <= a:
        break
else:
    ans.append(valid_nums[0])

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

Submission status: Wrong Answer

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

valid_nums = [i for i in range(10) if not i in D]
N = [int(n) for n in list(N)]
ans = []
for n in reversed(N):
    for i in range(0, 10-n):
        if n+i in valid_nums:
            ans.append(n+i)
            break
    else:
        ans.append(valid_nums[0])
else:
    if N[-1] > ans[-1]:
        ans.append(valid_nums[0])

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

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = [int(_) for _ in input().split()]
N = [int(n) for n in list(N)]
ans = []
for n in reversed(N):
    for i in range(0, 10-n):
        if n+i not in D:
            ans.append(n+i)
            break

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

Submission status: Wrong Answer

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

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

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

num = list(s.difference(d))

ans = [None]*len(n)

class Error():
    pass
        

for i in range(len(n)):
    if int(n[i]) in num:
        ans[i] = int(n[i])
    elif int(n[i]) < max(num):
        for item in num:
            if item > int(n[i]):
                ans[i] = item
            else:
                pass
        break
    else:
        for k in range(i-1,0,-1):
            for item in num:
                if item > int(n[k]):
                    ans[k] = item
                    for j in range(k + 1, len(ans)):
                        ans[j] = None
                    else:
                        raise Error()
for i in range(len(n)):
    if not ans[i]:
        ans[i] = min(num)

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

Submission status: Wrong Answer

Solution code:
N, K = raw_input().split()
D = set(map(int,raw_input().split()))
L = sorted(set(range(10))-D)

pay=[]
for ind, d in enumerate(N):
    if ind == 0:
        w = len(N)
        ma, mi = max(L), min(L)
        tmp = ''.join([str(ma)]*w)
        tmp = int(tmp)
        if tmp < int(N):
            if L[0]==0:
                pay = [str(L[1])]+['0']*w
            else:
                pay = [str(L[0])] * (w+1)
            break

    if int(d) in D:
        for l in sorted(L):
            if l > int(d):
                pay+= [str(l)]+[str(L[0])]*(w-len(pay)-1)
                break
        break

print ''.join(pay)

Submission status: Wrong Answer

Solution code:
N, K = raw_input().split()
D = set(map(int,raw_input().split()))
L = sorted(set(range(10))-D)

pay=[]
for ind, d in enumerate(N):
    if ind == 0:
        w = len(N)
        ma, mi = max(L), min(L)
        tmp = ''.join([str(ma)]*w)
        tmp = int(tmp)
        if tmp < int(N):
            if L[0]==0:
                pay = [str(L[1])]+['0']*w
            else:
                pay = [str(L[0])] * (w+1)
            break

    if int(d) in D:
        for l in sorted(L):
            if l > int(d):
                pay.append(str(l))
                break
        else:
            for l in sorted(L):
                if l > int(N[ind-1]):
                    pay=pay[:-1]+[str(l)]*(w-len(pay)+1)
                    break
            break

    else:
        pay.append(d)

print ''.join(pay)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = map(int, raw_input().split())
n = n[0]

d = map(int, raw_input().split())
e = range(0,10)
for dd in d:
    e.remove(dd)

sn = str(n)
indexes = deque()
for cn in sn:
    dn = int(cn)
    i = 0
    while i < len(e) and dn > e[i]:
        i+=1
    if i != len(e):
        indexes.append(i)
    else: # carry up
        j = -1
        while -j < len(indexes):
            if indexes[j] + 1 < len(e): # able to up
                indexes[j] += 1
                break
            else:
                indexes[j] = 0
            j -= 1
        # print j,indexes
        if -j >= len(indexes) : # one more digit
            indexes.clear()
            if e[0] != 0:
                indexes.append(0)
            else:
                indexes.append(1)
            for l in xrange(len(sn)):
                indexes.append(0)
            break

        indexes.append(0)
ans = ""
while len(indexes) != 0:
    i = indexes.popleft()
    ans += str(e[i])
    # print ans
print ans

Submission status: Wrong Answer

Solution code:
def check(n):
    return all(not int(i) in D for i in str(n))

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

for m in range(N, 10000):
    if check(m):
        print m
        break