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

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = int(result + (new_num - num) * math.pow(10, index-1))
            result_str = list(str(result))
        else:
            # print 'kuriage'
            result = int(result + (10 - num) * math.pow(10, index-1))
            result_str = list(str(result))
result = int(result)
while True:
    result_str = list(str(result))
    num = int(result_str[0])
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = int(result + (new_num - num) * math.pow(10, len(result_str)-1))
        else:
            result = int(result + (10 - num) * math.pow(10, len(result_str)-1))
    else:
        break

result_str = list(str(result))
base_str = list(str(amount))
for index in range(2, len(result_str)+1):
    num = int(result_str[-index])
    base_num = int(base_str[-index]) if index <= len(base_str) else None
    # print num, base_num
    if base_num is None or num > base_num:
        result_str[-index+1:len(result_str)] = ['0'] * (index - 1)
# print int(result)
print ''.join(result_str)

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:
        pay.append(d)

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 = [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:
        pay.append(d)

print ''.join(pay)

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())

min_v = float("inf")
for m in range(10000):
    if check(m) and m >= N:
        if m < min_v:
            min_v = m
print min_v

Submission status: Wrong Answer

Solution code:
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = int(result + (new_num - num) * math.pow(10, index-1))
            result_str = list(str(result))
        else:
            # print 'kuriage'
            result = int(result + (10 - num) * math.pow(10, index-1))
            result_str = list(str(result))
result = int(result)
while True:
    result_str = list(str(result))
    num = int(result_str[0])
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = int(result + (new_num - num) * math.pow(10, len(result_str)-1))
        else:
            result = int(result + (10 - num) * math.pow(10, len(result_str)-1))
    else:
        break
print int(result)

Submission status: Wrong Answer

Solution code:
N,K = map(int,raw_input().split())
D = raw_input().split()
cant = set(D)
for n in xrange(N,10000):
	u = set(list(str(n)))
	if len(cant - u) == K:
		print n
		break

Submission status: Wrong Answer

Solution code:
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = result + (new_num - num) * math.pow(10, index-1)
        else:
            # print 'kuriage'
            result += (10 - num) * math.pow(10, index-1)
            result_str = list(str(int(result)))
result = int(result)
while True:
    # print result
    result_str = list(str(result))
    # print result_str[0]
    if int(result_str[0]) in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = result + (new_num - num) * math.pow(10, len(result_str)-1)
        else:
            result += (10 - num) * math.pow(10, len(result_str)-1)
    else:
        break
print int(result)

Submission status: Wrong Answer

Solution code:
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = result + (new_num - num) * math.pow(10, index-1)
        else:
            # print 'kuriage'
            result += (10 - num) * math.pow(10, index-1)
result = int(result)
while True:
    # print result
    result_str = list(str(result))
    # print result_str[0]
    if int(result_str[0]) in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = result + (new_num - num) * math.pow(10, len(result_str)-1)
        else:
            result += (10 - num) * math.pow(10, len(result_str)-1)
    else:
        break
print int(result)

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:
        j = -1
        while indexes[j] + 1 < len(e):
            indexes[j] += 1
            j -= 1
            if j == -len(indexes):
                indexes.appendleft(0)

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

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()
e = 0
for i in range(10):
    if i not in d:
        e = i
        break

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while i >= 0:
        while s[i] in d:
            s[i] += 1
            for j in range(i+1,l):
                s[j] = e
        if s[i] > 9:
            if i != 0:
                s[i-1] += 1
                s[i] = e
        i -= 1
    if s[0] == 10:
        for i in range(1,10):
            if i not in d:
                s[0] = i*10+e
                if 0 not in d and i == e:
                    s[0] -= e
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = result + (new_num - num) * math.pow(10, index-1)
        else:
            # print 'kuriage'
            result += (10 - num) * math.pow(10, index-1)
while True:
    result_str = list(str(result))
    if result_str[0] in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = result + (new_num - num) * math.pow(10, len(result_str)-1)
        else:
            result += (10 - num) * math.pow(10, len(result_str)-1)
    else:
        break
print int(result)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()
e = 0
for i in range(10):
    if i not in d:
        e = i
        break

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while i >= 0:
        while s[i] in d:
            s[i] += 1
            for j in range(i+1,l):
                s[j] = e
        if s[i] > 9:
            if i != 0:
                s[i-1] += 1
                s[i] = e
        i -= 1
    if s[0] == 10:
        for i in range(1,10):
            if i not in d:
                s[0] = i*10+e
                if 0 not in d and i == e:
                    s[0] -+ e
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
N,K = raw_input().split()
K = int(K)
n = len(N)
l = [0] + map(int,list(N))
D = map(int,raw_input().split())
U = set(range(10)) - set(D)
flag = False
if l[1] in D:
	flag = True
	tmp = list(U - {l[1]})
	tmp.sort()
	if max(tmp) < l[1]:
		l[0] = min(list(U-{l[1],0}))
		l[1] = min(list(U-{l[1]}))
	else:
		for i in tmp:
			if i > l[1]:
				l[1] = i
				break
for i in xrange(2,n):
	ul = list(U)
	if flag:
		l[i] = min(ul)
	else:
		for low in ul:
			if low > l[i]:
				l[i] = low
				flag = True
				break
print int("".join(map(str,l)))

Submission status: Wrong Answer

Solution code:
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = result + (new_num - num) * math.pow(10, index-1)
        else:
            # print 'kuriage'
            result += (10 - num) * math.pow(10, index-1)
result_str = list(str(result))
if result_str[0] in avoids:
    new_num = None
    for x in non_avoids:
        if x > num:
            new_num = x
            break
    if new_num:
        result = result - (new_num - num) * math.pow(10, len(result_str)-1)
    else:
        result += (10 - num) * math.pow(10, len(result_str)-1)
print int(result)

Submission status: Wrong Answer

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

pay=[]
for d in str(N):
    if int(d) in D:
        for l in sorted(L):
            if l > int(d):
                pay.append(str(l))
                break
    else:
        pay.append(d)

print ''.join(pay)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, K = ln()
D = ln()
f = set(map(str, D))

for i in xrange(N, 10000):
    s = set(str(i))
    if len(s & f) == 0:
        print i
        break

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()
e = 0
for i in range(10):
    if i not in d:
        e = i
        break

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while i >= 0:
        while s[i] in d:
            s[i] += 1
            for j in range(i+1,l):
                s[j] = e
        if s[i] > 9:
            if i != 0:
                s[i-1] += 1
                s[i] = e
        i -= 1
    if s[0] == 10:
        for i in range(1,10):
            if i not in d:
                s[0] = i*10+e
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()
e = 0
for i in range(10):
    if i not in d:
        e = i
        break

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while i >= 0:
        while s[i] in d:
            s[i] += 1
        if s[i] > 9:
            for j in range(i+1,l):
                s[j] = e
            if i != 0:
                s[i-1] += 1
                s[i] = e
        i -= 1
    if s[0] == 10:
        for i in range(1,10):
            if i not in d:
                s[0] = i*10+e
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while i >= 0:
        while s[i] in d:
            s[i] += 1
        if s[i] > 9:
            for j in range(i+1,l):
                s[j] = 0
            if i != 0:
                s[i-1] += 1
                s[i] = 0
        i -= 1
    if s[0] == 10:
        for i in range(1,10):
            if i not in d:
                s[0] = i*10
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while i >= 0:
        while s[i] in d:
            s[i] += 1
        if s[i] > 9:
            for j in range(i+1,l):
                s[j] = 0
            if i != 0:
                s[i-1] += 1
                s[i] = 0
        i -= 1
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

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

d.sort()

a = list(map(int, str(n)))
s = a[:]
l = len(s)
for i in range(l+1):
    if i == l:
        break
    if s[i] in d:
        break
if i == l:
    print(n)
else:
    while s[i] in d:
        s[i] += 1
    if s[i] > 9:
        for j in range(i+1,l):
            s[j] = 0
        if i != 0:
            s[i-1] += 1
            s[i] = 0
    print("".join(list(map(str, s))))

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
is_bad = [ False for d in range(10) ]
for d in map(int, raw_input().split()):
  is_bad[d] = True

def good(x):
  while x != 0:
    d = x % 10
    if is_bad[d]:
      return False
    x //= 10
  return True

while True:
  n += 1
  if good(n):
    print(n)
    break

Submission status: Wrong Answer

Solution code:
from itertools import product
N, K = list(map(int, input().split()))
D = set(range(10)) - set(list(map(int, input().split())))
ans = float("inf")
for i in range(1):
    for s in product(D, repeat=len(str(N))+i):
        n = int("".join(map(str, s)))
        if n >= N and ans - N > n - N:
            ans = n
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, K = ln()
D = ln()
f = set(map(str, D))

for i in xrange(N, 10001):
    s = set(str(i))
    if len(s & f) == 0:
        print i
        break

Submission status: Time Limit Exceeded

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

n = N
while True:
    if set(str(n)) in D:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N, K = i_map()
    D = i_list()

    for i in range(N,10*N+1):
        t = str(i)
        flg = True
        for j in D:
            if str(j) in t:
                flg = False
        if flg == True:
            print(i)
            exit()


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
s = s.split(" ")
N = s[0]
K = int(s[1])

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

minNum = min([digit for digit in range(0, 10) if digit not in ds])
nonZerominNum = min([digit for digit in range(1, 10) if digit not in ds])
maxNum = max([digit for digit in range(0, 10) if digit not in ds])

digits = [int(digit) for digit in N]

result = N
for index in range(0, len(digits)):
  digit = digits[index]
  if digit in ds:
    i = index
    if digit > maxNum:
      i = index - 1
      while i >= 0 and digits[i] == maxNum:
        i -= 1
    
    if i < 0:
      result = str(nonZerominNum) + (str(minNum) * len(N))
    else:
      biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]])
      digits[i] = biggerDigit
      for j in range(i+1, len(digits)):
        digits[j] = minNum
      result = "".join([str(digit) for digit in digits])
    break

print(result)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n,100000):
    s=str(i)
    d=list(map(int,s))
    f=0
    for j in range(len(d)):
        if(d[j] in l):
            f=1
    if(f==0):
        print(i)
        exit()

Submission status: Accepted

Solution code:
N, K=map(int,input().split())
D=list(map(int,input().split()))
for i in range (N,100000):
    a=str(i)
    b=list(map(int,a))
    l=len(b)
    c=0
    for j in range(l):
        if(b[j] in D):
            c=1
    if(c==0):
        ans=i
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, K =MI()
    num = [1] * 10
    for m in LI():
        num[m] = 0
    # print(num)

    def check(x):
        s = set(list(str(x)))
        return all([num[int(i)] for i in s])

    while 1:
        if check(N):
            print(N)
            return
        N += 1
    

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n,k=map(int,input().split())
D=list(map(str,input().split()))

for i in range(n,10**6):
    if any([j in D for j in str(i)]) ==0:
        print(i);exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
w = [False] * 10
for i in d:
	w[i] = True
def check(n):
	while n:
		if w[n % 10]:
			return False
		n //= 10
	return True
ans = n
while not check(ans):
	ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, k =map(int, input().split())
d = list(map(int, input().split()))
a = [0]*10
for i in d:
  a[i]=1
  
ans = n
while True:
  flg = False
  temp = str(n)
  l = len(temp)
  for i in range(l):
    if a[int(temp[i])]==1:
      n+=1
      flg = True
      break
  if flg:
    continue
  else:
    print(n)
    quit()

Submission status: Accepted

Solution code:
def ume(n):
  st = str(n)
  le = len(st)
  re = ["0"]*le
  for i in range(le):
    if st[i]=="0":
      re[i]=str(m)
    else:
      re[i]=st[i]
  return int("".join(re))


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

#使える文字をリスト化
for i in range(10):
  if not i in d:
    num.append(i)

ds = str(n)#nを文字列にしたもの
l = len(ds)#nの桁数
m = min(num)#numのうち最小の数

if l == 1:
  for i in num:
    if i>=n:
      print(i)
      quit()

dp1=[0]*(l+1)

for i in num:
  if i != 0:
    ans = ume(i*(10**(l)))
    break

for i in num:
  flg = True
  if i == int(ds[0]):
    dp1[1]=i*(10**(l-1))
    flg = False
  if i > int(ds[0]):
    ans = ume(i*(10**(l-1)))
    break
    
if flg:
  print(ans)
  quit()

for i in range(1, l):
  flg = True
  flg2 = True
  for j in num:
    if j == int(ds[i]):
      dp1[i+1]=dp1[i]+j*(10**(l-1-i))
      flg = False
      flg2 = False
      break
    if j > int(ds[i]):
      flg2 = False
      ans = ume(dp1[i]+j*(10**(l-1-i)))
      if flg:
        print(ans)
        quit()
      break
  if flg2:
    print(ans)
    quit()
  #print(dp1[i+1])
print(dp1[l])

Submission status: Accepted

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

def is_ok(num):
  s = str(num)
  for ng in d:
    if ng in s: return False
  
  return True

while True:
  if is_ok(n):
    print(n)
    exit()
  
  n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ar=list(map(int,input().split()))
def f(n):
    s=str(n)
    for el in ar:
        if(str(el) in s):
            return 0
    return 1
while(not f(n)):
    n+=1
print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D=set(map(str,input().split()))
ans=''
while True:
    tmp=set(list(str(n)))
    if len(D&tmp)==0:
        ans=n
        break
    n+=1
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
n,k=map(int,input().split())
d=input().split()
i=n
while True:
  for j in str(i):
    if j in d:
      i+=1
      break
  else:
    print(i)
    break

Submission status: Accepted

Solution code:

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

ans = n
while True:
    check = True
    for dk in d:
        if dk in str(ans):
            check = False
            break
    if check:
        break
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

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

from queue import deque
q = deque([0])
while True:
    n = q.popleft()
    if n>=N:
        break
    for i in kouho:
        q.append(n*10+i)
print(n)

Submission status: Accepted

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

for i in range(n,100000):
    k = i
    c=0
    while k>0:
        if k%10 not in l:
            c+=1
        else:
            break
        k = k//10
    if len(str(i))==c:
        print(i)
        break

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*d = map(int,read().split())


suki = [1]*10
for i in d: suki[i]=0

def check(i):
    while i:
        r = i%10
        if suki[r]==0: return False
        i//=10
    return True    

ans = 10**7
for i in range(10**6,0,-1):
    if i < n: break
    if check(i): ans = i

    
print(ans)

Submission status: Accepted

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

i = n
while True:
    if (i >= n) and all(int(j) in d for j in str(i)):
        print(i)
        break
    i += 1

Submission status: Accepted

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

i = n
while True:
    if (i >= n) and all(int(k) in d for k in str(i)):
        print(i)
        break
    i += 1

Submission status: Accepted

Solution code:
from itertools import product

n, k = map(int, input().split())
d = set(range(10)) - set(map(int, input().split()))

for i in product(d | set([0]), repeat=len(str(n)) + 1):
    i = int("".join(str(j) for j in i))
    if (i >= n) and all(int(k) in d for k in str(i)):
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = tuple(input().split())
while True:
    sn = str(n)
    for s in sn:
        if s in D:
            break
    else:
        break

    n += 1

print(n)