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())
d_list = list(map(int, input().split()))
num_list = [0,1,2,3,4,5,6,7,8,9]

for d in d_list:
  num_list.remove(d)

final_price = ''

def is_dislike_number(number, dislike_list):
  if number in dislike_list:
    return True
  else:
    return False

for i, num in enumerate(str(n)):
  num = int(num)
  if is_dislike_number(num, d_list):
    while num < 10:
      num += 1
      digit = len(str(n)) - i - 1
      if not is_dislike_number(str(num), d_list):
        final_price += str(num)
        for j in range(digit):
          final_price += str(num_list[0])
        print(final_price)
        exit()

  final_price += str(num)
print(final_price)

Submission status: Wrong Answer

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

num_list = list(map(int,input().split()))
while(True):
    flag=True;
    num=n
    while(num!=0):
        for i in num_list:
            if(num//10 == i):
                flag=False
        num = num/10
    if(flag==True):
        print(n)
        break
    else :
        n=n+1

Submission status: Wrong Answer

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

ans = N
while True:
    ch_n = str(ans)
    for c in ch_n:
        if c in D:
            break
        print(ans)
        exit()
    ans += 1

Submission status: Wrong Answer

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

while True:
    ch_n = str(N)
    for c in ch_n:
        if int(c) in D:
            break
        print(N)
        exit()
    N += 1

Submission status: Wrong Answer

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

n = len(str(N))

for i in range(1,10):
    if i not in D:
        print(str(i)*(n+1))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
d = list(map(int, input().split()))
check = [False]*10
for i in range(k):
    check[d[i]] = True

def judge(x):
    while x > 0:
        if check[x%10]:
            return False
        x //= 10
    return True

if judge(n):
    ans = n
else:
    min_allow = 0
    for i in range(10):
        if not check[i]:
            min_allow = i
            break

    ans = 0
    l = len(str(n))-1
    top = n//(10**l)
    for i in range(top, top+10):
        if i%10 == 0:
            continue
        if not check[i%10]:
            if i > 10:
                l += 1
            ans = (i%10)*10**l
            break

    for i in range(l):
        ans += min_allow*10**i
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
d = list(map(int, input().split()))
check = [False]*10
for i in range(k):
    check[d[i]] = True

def judge(x):
    while x > 0:
        if check[x%10]:
            return False
        x //= 10
    return True

if judge(n):
    ans = n
else:
    min_allow = 0
    for i in range(10):
        if not check[i]:
            min_allow = i
            break

    ans = 0
    l = len(str(n))-1
    top = n%(10**l)
    new_top = 0
    for i in range(top, top+10):
        if i%10 == 0:
            continue
        if not check[i%10]:
            if i > 10:
                l += 1
            ans = (i%10)*10**l
            break

    for i in range(l):
        ans += min_allow*10**i
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = set(range(10))
d = set([int(i) for i in input().split()])
b = a - d
k = {}
c = 0
n = N
while n:
    n, r = divmod(n, 10)
    k[c] = r
    c += 1

ans = 0
l = len(k.keys())

for i, j in enumerate(sorted(k.keys())):
    if j != (l-1) and not k[j] in b:
        ans += 10**j * min(b)
    elif j == (l-1) and not k[j] in b:
        if k[j] > max(b):
            ans += 10**(j+1) * min(b-{0}) + 10**(j) *min(b)
        else:
            for a in sorted(list(b)):
                if k[j] < a:break
            ans += 10**j * a
    else:
        ans += 10**j * k[j]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = set(range(10))
d = set([int(i) for i in input().split()])
b = a - d
k = {}
c = 0
n = N
while n:
    n, r = divmod(n, 10)
    k[c] = r
    c += 1

ans = 0
l = len(k.keys())

for i, j in enumerate(sorted(k.keys())):
    if j != (l-1) and not k[j] in b:
        ans += 10**j * min(b)
    elif j == (l-1) and not k[j] in b:
        if k[j] > max(b):
            ans += 10**(j+1) * min(b-{0}) + 10**(j) *min(b-{0})
        else:
            for a in sorted(list(b)):
                if k[j] < a:break
            ans += 10**j * a
    else:
        ans += 10**j * k[j]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = set(range(10))
d = set([int(i) for i in input().split()])
b = a - d
k = {}
c = 0
n = N
while n:
    n, r = divmod(n, 10)
    k[c] = r
    c += 1

ans = 0
l = len(k.keys())

for i, j in enumerate(sorted(k.keys())):
    if j != (l-1) and not k[j] in b:
        ans += 10**j * min(b)
    elif j == (l-1) and not k[j] in b:
        if k[j] > max(b):
            ans += 10**(j+1) * min(b) + 10**(j) *min(b)
        else:
            for a in sorted(list(b)):
                if k[j] < a:break
            ans += 10**j * a
    else:
        ans += 10**j * k[j]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = set(range(10))
d = set([int(i) for i in input().split()])
b = a - d
k = {}
c = 0
n = N
while n:
    n, r = divmod(n, 10)
    k[c] = r
    c += 1

ans = 0
l = len(k.keys())

for i, j in enumerate(sorted(k.keys())):
    if j != (l-1) and not k[j] in b:
        ans += 10**j * min(b)
    elif j == (l-1) and not k[j] in b:
        if k[j] > max(b):
            ans += 10**(j+1) * min(b)
        else:
            for a in sorted(list(b)):
                if k[j] < a:break
            ans += 10**j * a
    else:
        ans += 10**j * k[j]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    c = list(set(range(10)).difference(d))
    c.sort()

    num, success = sup(n, c)
    if success:
        ans = num
    else:
        c_min = c[0]
        ans = c_min*10000 + c_min*1000 + c_min*100 + c_min*10 + c_min

    print(ans)


def sup(n, c):
    for i1 in c:
        for i2 in c:
            for i3 in c:
                for i4 in c:
                    num = i1*1000 + i2*100 + i3*10 + i4
                    if n <= num:
                        return num, True
    return None, False


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def find_next_valid_digit(d, bad_nums):
    next_digit = d
    while True:
        next_digit = next_digit + 1
        valid = True
        for c in str(next_digit):
            if int(c) in bad_nums:
                valid = False
                break
        if valid:
            break
    return next_digit

if __name__ == '__main__':
    n, k = list(map(int, input().split(' ')))
    bad_nums = list(map(int, input().split(' ')))
    n_str = str(n)
    cur_result = 0
    for i in range(len(n_str)):
        most_significant_digit = int(n_str[i])
        if most_significant_digit in bad_nums:
            basis = cur_result * 10 + most_significant_digit
            cur_result = find_next_valid_digit(basis, bad_nums)
            cur_result = cur_result * (10 ** (len(n_str) - i - 1))
            break
        else:
            cur_result = cur_result * 10 + most_significant_digit

    print(cur_result)

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())
number = [int(i) for i in input().split()]
answer = 0
list_n = str(n)
count = list(map(int, list_n))
 

def check(true_number, answer):
    answer = str(answer)
    for i in true_number:
        if str(i) in answer:
            break
        else:
            return False
    return True

true_number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in number:
    if i in true_number:
        true_number.remove(i)
 
answer = n
while 1:
    if  check(true_number, answer):
        break
    else:
        answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())
number = [int(i) for i in input().split()]
answer = []
list_n = str(n)
count = list(map(int, list_n))
 
true_number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in number:
    if i in true_number:
        true_number.remove(i)
 
 
 
flag  = 0
for j in count:
    for i in true_number:
        if j < i:
            answer.append(i)
            flag=1
            break   
        elif flag == 1 and true_number.count(0) == 1:
            answer.append(0)
            break
        elif j == i:
            answer.append(i)
            flag =0
            break
print(''.join(map(str, answer)))

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())
number = [int(i) for i in input().split()]
answer = []
list_n = str(n)
count = list(map(int, list_n))

true_number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in number:
    if i in true_number:
        true_number.remove(i)



flag  = 0
for j in count:
    for i in true_number:
        if j < i:
            answer.append(i)
            flag=1
            break   
        elif flag == 1 and true_number.count(0):
            answer.append(0)
            break
        elif j == i:
            answer.append(i)
            flag =0
print(''.join(map(str, answer)))

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())
number = [int(i) for i in input().split()]
answer = []
list_n = str(n)
count = list(map(int, list_n))

true_number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in number:
    if i in true_number:
        true_number.remove(i)

for j in count:
    for i in true_number:
        if j <= i:
            answer.append(i)
            break   

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

Submission status: Wrong Answer

Solution code:
import math
l = list(map(int,input().split()))
n = l[0]
k = l[1]
d = list(map(int,input().split()))
hoge = list(range(10))
for i in d:
    hoge.remove(i)
dig = math.ceil(math.log(n,10))
po = 0
for i in range(dig):
    po += hoge[len(hoge)-1]*(10**i)
ans = 0
if po < n:
    if 0 in hoge:
        print(hoge[1]*(10**dig))
    else:
        for i in range(dig+1):
            ans += ans*10+hoge[0]
        print(ans)
else:
    for i in range(dig):
        r = n%10
        for j in hoge:
            if r <= j:
                ans+=j*(10**i)
                break
        n=math.floor(n/10)
    print(ans)

Submission status: Wrong Answer

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

    for i in range(10):
        if i not in D:
            min_ = i
            break

    k = 10 ** (len(str(N)) - 1)
    ans = []
    apnd = ans.append
    num, flag = N, 0
    while k > 0:
        if not flag:
            while num // k in D:
                num += k
                if num // k > 9:
                    k *= 10
                flag = 1
            d, num = divmod(num, k)
            apnd(d)
        else:
            apnd(min_)
        k //= 10

    print(*ans, sep='')

main()

Submission status: Wrong Answer

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

    ans = []
    apnd = ans.append
    num = N
    while num > 0:
        while num % 10 in D:
            num += 1
        num, m = divmod(num, 10)
        apnd(m)

    print(*ans[::-1], sep='')

main()

Submission status: Wrong Answer

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

    k = len(str(N))
    ans = [0] * k
    num = N
    for i in range(1, k + 1):
        while num % 10 in D:
            num += 1
        num, ans[k-i] = divmod(num, 10)

    print(*ans, sep='')

main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai = N
l = [int(x) for x in list(str(N))]
c = len(l)
for i in range(len(l)):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
if len(l)==c+1:
        while l[c] in D:
            shiharai+=1
            l = [int(x) for x in list(str(shiharai))]
print(shiharai)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
c=len(l)
for i in range(len(l)):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
if len(l)!=c:
    for i in range(len(l)):
        while l[i] in D:
            shiharai+=1
            l = [int(x) for x in list(str(shiharai))]
print(shiharai)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
c=len(l)
for i in range(len(l)):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
if len(l)!=c:
    while l[len(l)-1] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]     
print(shiharai)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
c=len(l)
for i in range(len(l)):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
    if len(l)!=c:
        while l[len(l)-1] in D:
            shiharai+=1
            l = [int(x) for x in list(str(shiharai))]            
print(shiharai)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
c=len(l)
for i in range(len(l)):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
    if len(l)!=c:
        while l[len(l)-1] in D:
            shiharai+=1

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
for i in range(len(l)):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
print(shiharai)

Submission status: Wrong Answer

Solution code:
n, k = input().split()
o = map(int, input().split())
nums = map(int, list(n))
l = []
for v in nums:
    while v in o:
        v += 1
    l.append(v)
print(''.join(map(str, l)))

Submission status: Wrong Answer

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, k = list(map(str, input().split()))
    d = list(map(str, input().split()))
    numbers = [str(i) for i in range(0, 10)]
    like_numbers = set(numbers) - set(d)

    for i in like_numbers:
        for j in like_numbers:
            for k in like_numbers:
                for l in like_numbers:
                    number_candidate = i + j + k + l

                    if number_candidate >= n:
                        print(number_candidate)
                        exit()

    print(int(n) + 1)

Submission status: Wrong Answer

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, k = list(map(str, input().split()))
    d = list(map(str, input().split()))
    numbers = [str(i) for i in range(0, 10)]
    like_numbers = set(numbers) - set(d)

    for i in like_numbers:
        for j in like_numbers:
            for k in like_numbers:
                for l in like_numbers:
                    number_candidate = i + j + k + l

                    if number_candidate >= n:
                        print(number_candidate)
                        exit()

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)

def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero and 0 in [i,j,k,l,m]:
                                if i != 0:
                                    continue
                                    if 0 in [j,k,l,m] and j != 0:
                                        continue
                                        if 0 in [k,l,m] and k != 0:
                                            continue
                                            if 0 in [l,m] and l != 0:
                                                continue
                            print(money)
                            return 0

lowest()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
T=[0 for i in range(10)]
for i in D:
    T[i]=1
S=[]
for i in range(10):
    if T[i]==0:
        S.append(i)
import itertools
L=list(itertools.product(S,S,S,S))
R=sorted([int(str(i[0])+str(i[1])+str(i[2])+str(i[3])) for i in L])
for i in R:
    if i>=N:
        print(i)
        exit()
if S[0]!=0:
    print(str(S[0])*5)
else:
    print(str(S[1])+"0000")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
T=[0 for i in range(10)]
for i in D:
    T[i]=1
S=[]
for i in range(10):
    if T[i]==0:
        S.append(i)
import itertools
L=list(itertools.product(S,S,S,S))
R=sorted([int(str(i[0])+str(i[1])+str(i[2])+str(i[3])) for i in L])
for i in R:
    if i>=N:
        print(i)
        exit()
print(str(min(S))*5)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
T=[0 for i in range(10)]
for i in D:
    T[i]=1
S=[]
for i in range(10):
    if T[i]==0:
        S.append(i)
import itertools
L=list(itertools.product(S,S,S,S))
R=sorted([int(str(i[0])+str(i[1])+str(i[2])+str(i[3])) for i in L])
for i in R:
    if i>=N:
        print(i)
        exit()
print(min(S)*5)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
T=[0 for i in range(10)]
for i in D:
    T[i]=1
S=[]
for i in range(10):
    if T[i]==0:
        S.append(i)
import itertools
L=list(itertools.product(S,S,S,S))
R=[int(str(i[0])+str(i[1])+str(i[2])+str(i[3])) for i in L]
for i in R:
    if i>=N:
        print(i)
        exit()
print(min(S)*5)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = input().split()
for i in range(N-1, N*100):
    for j in str(i):
        if j in a:
            break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
d = [int(i) for i in input().split()]
for i in range(n,10000):
	a = str(i)
	if all(int(j) not in d for j in a):
		print(i)
		break

Submission status: Wrong Answer

Solution code:
from functools import reduce

def obsession(n, disliked):
    def nearest(digit):
        for i in range(digit, digit + 10):
            mod10 = i % 10
            if mod10 not in disliked:
                return (mod10, i != mod10)

    will_pay = list(map(int, str(n)))
    index = 0
    while index < len(will_pay):
        digit = will_pay[index]
        if digit in disliked:
            substitute, carry = nearest(digit)
            will_pay[index] = substitute
            while carry and index > 0:
                substitute, carry = nearest(will_pay[index - 1] + 1)
                will_pay[index - 1] = substitute
                index -= 1
            if carry:
                will_pay.insert(0, nearest(1)[0])
                index += 1
        index += 1
    return reduce(lambda x, y: x * 10 + y, will_pay, 0)


if __name__ == '__main__':
    n, _ = map(int, input().split())
    disliked = set(map(int, input().split()))
    print(obsession(n, disliked))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(input().split())
for i in range(N, 10001):
    string = set(str(i))
    for s in string:
        if s in D:
            break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(input().split())
array = set(str(i) for i in range(10)) - D
for i in range(N, 10001):
    string = set(str(i))
    for s in string:
        if s in array:
            continue
        break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = set(map(int,input().split()))
x = len(str(n))
for i in range(x):
    while (n//(10**i))%10 in d:
        n += 10**i
urad = {1,2,3,4,5,6,7,8,9} - d
if len(str(n)) != x and 1 in d:
    n += (min(urad)-1)*(10**x)
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = set(map(int,input().split()))
x = len(str(n))
for i in range(x):
    while (n//(10**i))%(10**(i+1)) in d:
        n += 10**i
urad = {1,2,3,4,5,6,7,8,9} - d
if len(str(n)) != x and 1 in d:
    n += (min(urad)-1)*(10**x)
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = set(map(int,input().split()))
x = len(str(n))
for i in range(x):
    while (n//(10**i))%(10**(i+1)) in d:
        n += 10**i
urad = {1,2,3,4,5,6,7,8,9} - d
if len(str(n)) != x :
    n += (min(urad)-1)*(10**x)
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = set(map(int,input().split()))
x = len(str(n))
for i in range(x):
    while (n//(10**i))%(10**(i+1)) in d:
        n += 10**i
urad = {1,2,3,4,5,6,7,8,9} - d
if len(str(n)) != x and 1 in d:
    n += (min(d)-1)*(10**x)
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = set(map(int,input().split()))
x = len(str(n))
for i in range(x):
    while (n//(10**i))%(10**(i+1)) in d:
        n += 10**i
urad = {1,2,3,4,5,6,7,8,9} - d
if len(str(n)) != x and 1 in d:
    n += min(d)*(10**x)
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = set(map(int,input().split()))
x = len(str(n))
for i in range(x):
    while (n//(10**i))%(10**(i+1)) in d:
        n += 10**i
urad = {1,2,3,4,5,6,7,8,9} - d
if 1 in d:
    n += min(d)*(10**x)
print(n)

Submission status: Wrong Answer

Solution code:
import itertools

N, K = [int(s) for s in input().split()]
D = [int(s) for s in input().split()]
U = [str(n) for n in range(10) if n not in D]

ret = N * 10
for v in [int(''.join(T)) for T in itertools.product(U, repeat=4)]:
    if N <= v:
        ret = min(ret, v)
print(ret)

Submission status: Wrong Answer

Solution code:
import itertools

N, K = [int(s) for s in input().split()]
D = [int(s) for s in input().split()]
U = [str(n) for n in range(10) if n not in D]

ret = N * 10
for v in [int(''.join(T)) for T in itertools.product(U, repeat=4)]:
    print(v)
    if N <= v:
        ret = min(ret, v)
print(ret)

Submission status: Wrong Answer

Solution code:
def c_IrohaObsession(N, K, D):
    d = [str(i) for i in D]
    i = N
    while True:
        for c in str(i):
            if c in d:
                break
        else:
            return i
        i += 1

Submission status: Wrong Answer

Solution code:
def c_IrohaObsession(N, K, D):
    d = [str(i) for i in D]
    for i in range(N, 10000):
        for c in str(i):
            if c in d:
                break
        else:
            break
    return i

N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_IrohaObsession(N, K, D))

Submission status: Wrong Answer

Solution code:
(n, k), d = map(int, raw_input().split()), set(raw_input().split())
for _ in xrange(n, 10000):
    if not set(str(_)) & d:
        print _
        break

Submission status: Wrong Answer

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

num = input().split()

for i in range(n, 10000):
    flug = True
    istr = str(i)
    for j in range(len(istr)):
        if istr[j] in num:
            flug = False
            break
        else:
            pass
    if flug:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n=int(input().split()[0])
d=input()
k=1
while k <= n:
    if str((n//k)%10) in d:
        n+=k
    else:
        k*=10
print(n)

Submission status: Wrong Answer

Solution code:
N,K=map(int,raw_input().split())
D=map(int,raw_input().split())
n=[0,1,2,3,4,5,6,7,8,9]

a=[]	#Allowed numbers
for i in n:
	if i not in D:
		a.append(i)


for i in range(N,10000):
	for j in D:
		if str(i).find(str(j))!=-1:
			break
	else:
		print str(i)
		break

Submission status: Wrong Answer

Solution code:
N,K=map(int,raw_input().split())
D=map(int,raw_input().split())
n=[0,1,2,3,4,5,6,7,8,9]

a=[]	#Allowed numbers
for i in n:
	if i not in D:
		a.append(i)


for i in range(N,10001):
	for j in D:
		if str(i).find(str(j))!=-1:
			break
	else:
		print str(i)
		break

Submission status: Wrong Answer

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

t = 1
while n >= t:
    digit = int((n / t) % 10)
    if digit not in d:
        t *= 10
        continue
    while digit in d:
        n += t
        digit = int((n / t) % 10)
    t *= 10
print(n)

Submission status: Wrong Answer

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

def digits(n):
  res = set()
  while n > 0:
    res = res.union(set([n%10]))
    n //= 10
  return res

n = 1
while True:
  if digits(N*n).isdisjoint(D):
    print(N*n)
    break
  n+=1

Submission status: Wrong Answer

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

"""042-c"""

import sys


def solve(dislike_digits_table, first_like_digit, N):
    """Solve."""
    for i, c in enumerate(N):
        while dislike_digits_table[int(c)]:
            if c == '9':
                if i == 0:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 '1' + '0' * len(N))
                else:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 N[0:i] + '0' * len(N[i:]))
            else:
                c = chr(ord(c) + 1)
        N = N[0:i] + c + N[i + 1:]

    return N


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                            in enumerate(dislike_digits_table)
                            if not v))

    print(solve(dislike_digits_table, first_like_digit, N))


if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

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

"""042-c"""

import sys

def solve(dislike_digits_table, first_like_digit, number):
    """Solve."""
    if dislike_digits_table[int(number[0])]:
        while dislike_digits_table[int(number[0])]:
            if number[0] == '9':
                number = '10' + number[1:]
            else:
                number = "{0}{1}".format(chr(ord(number[0]) + 1), number[1:])
        number = number.replace(number[1:], first_like_digit * (len(number) - 1))

    return number


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                            in enumerate(dislike_digits_table)
                            if not v))

    for i, d in enumerate(N):
        if dislike_digits_table[int(d)]:
            N = N.replace(N[i:], solve(dislike_digits_table, first_like_digit, N[i:]))
            break

    print(N)


if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
import sys
N,K = list(map(int,input().split()))
D = input().split()
while True:
    for i in range(len(str(N))):
        if str(N)[i] in D:
            break
        else:
            print(N)
            sys.exit()
    N += 1

Submission status: Wrong Answer

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

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

A = [i for i in L]

for i in L:
  for j in L:
    A.append(10*i+j)
for  i in L:
  for j in L:
    for k in L:
      A.append(100*i+10*j+k)
for i in L:
  for j in L:
    for k in L:
      for l in L:
        A.append(1000*i+100*j+10*k+l)
A.sort()
for i in A:
  if i >= N:
    print(i)
    break

Submission status: Wrong Answer

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

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

A = [i for i in L]

for i in L:
  for j in L:
    A.append(10*i+j)
for  i in L:
  for j in L:
    for k in L:
      A.append(100*i+10*j+k)
for i in L:
  for j in L:
    for k in L:
      for l in L:
        A.append(1000*i+100*j+10*k+l)

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