Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Accepted

Solution code:
import collections, heapq, math, sys

n, k = map(int, sys.stdin.readline().rstrip().split(' '))
dislikes = map(int, sys.stdin.readline().rstrip().split(' '))
dislikess= set(dislikes)
for i in range(9):
  if i not in dislikess:
    smallest = i
    break
cp = n
s = []
while cp:
  s.append(cp%10)
  cp //= 10
s.append(0)
idx = -1
found = True
for i in range(len(s)):
  z = s[i]
  if i == len(s) - 1:
    if not found:
        if smallest == 0:
            for m in range(1, 10):
                if m not in dislikess:
                    s[i] = m
                    break
        else:
            s[i] = smallest
        idx = i-1
    break
  if not found or z in dislikess:
    found = False
    for j in range(z+1, 10):
      if j not in dislikes:
        s[i] = j
        found = True
        break
    if not found:
    	idx = i
    else:
    	idx = i - 1
  else:
    found = True
if s[-1] == 0:
  s.pop()
for i in range(idx+1):
  s[i] = smallest

ret = 0
while len(s):
  ret *= 10
  ret += s.pop()
print(ret)

Submission status: Accepted

Solution code:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
s =set(map(int, input().split()))
pay = n
while True:
    check = set([int(i) for i in str(pay)])
    if s.isdisjoint(check):
        break
    else:
        pay +=1
print(pay)

Submission status: Accepted

Solution code:
import sys
def c():
    p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
    N, K = p[0]
    D = p[1]
    #print(N, D)
    while True:
        n = N
        while True:
            if n % 10 in D:
                N = N + 1
                break
            #print("mod: ", n % 10)
            n = int(n / 10)
            if n == 0:
                print(N)
                quit()
c()

Submission status: Accepted

Solution code:
#coding: utf-8
n, k = map(int, input().split())
D = list(map(str, input().split()))
#print(D)
for i in range(n, 100000):
    tmp = list(str(i))
    cnt = 0
    for j in range(len(tmp)): 
        #print("tmp[j] =", tmp[j], type(tmp[j]))
        if tmp[j] in D:
            cnt += 1
    #print(cnt)
    if cnt == 0 and i >= n:
        print(i)
        break

Submission status: Accepted

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

while True:
    flag = True
    now = str(N)
    for i in range(K):
        if D[i] in now:
            flag = False
    if flag:
        break
    N += 1
print(now)

Submission status: Accepted

Solution code:
N,M= [ int(it) for it in input().split() ]
A = [ int(it) for it in input().split() ]

for i in range(N,10000000000000):
  n = i
  flag = True
  for j in range(1000000):
    if (n%10 in A ):
      flag = False
      break
    n//=10
    if (n==0):
      break
  if (flag):
    print (i)
    break

Submission status: Accepted

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

Submission status: Accepted

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

for cost in range(N,10*N+1):
    s = set(list(str(cost)))
    if len(D & s) == 0:
        print(cost)
        exit()

Submission status: Accepted

Solution code:
import sys

N, K = map(int,input().split())
D = list(input().split())
for i in range(N, 100001):
    flg = 1
    cost = str(i)
    digit = len(cost)
    for j in range(digit):
        if cost[j] in D:
            flg = 0
            break
    if flg == 1:
        print(cost)
        sys.exit()
print("error")

Submission status: Accepted

Solution code:
n,a=open(0);n=int(n.split()[0])
while set(a)&set(str(n)):n+=1
print(n)

Submission status: Accepted

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

def check(x, D):
    while x > 0:
        x, k = divmod(x, 10)
        if k in D:
            return False
    return True

result = N

while 1:
    if check(result, D):
        break
    result += 1

print(result)

Submission status: Accepted

Solution code:
import itertools

N, K = map(int, input().split())
Ds = list(map(int, input().split()))
NDs = list(set([i for i in range(10)]) - set(Ds))
NDs = list(map(str, NDs))

min_price = 100000
for p in itertools.product(NDs, repeat=len(str(N))):
    if p[0] == '0':
        continue
    price = int(''.join(p))
    if price < N:
        continue
    min_price = min(price, min_price)

if min_price == 100000:
    for p in itertools.product(NDs, repeat=len(str(N))+1):
        if p[0] == '0':
            continue
        price = int(''.join(p))
        min_price = min(price, min_price)

print(min_price)

Submission status: Accepted

Solution code:
N,K=map(int,input().split(' '))
D=list(map(str,input().split(' ')))
ans=N
while True:
  judge=True
  m=len(str(ans))
  for i in range(m):
    if str(ans)[i] in D:
      judge=False
      break
    else:
      continue
  if judge==False:
    ans+=1
    continue
  else:
    break
print(ans)

Submission status: Accepted

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

for i in range(n,88889):
  for j in str(i):
    if int(j) in D:
      break
  else:
    print(i)
    exit()

Submission status: Accepted

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

for i in range(N,100000):
    for d in D:
        if d in str(i):
            break
    else:
        break
    continue
print(i)

Submission status: Accepted

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

for i in range(N, 100000):
    S = set(list(str(i)))
    for j in S:
        if j in D:
            break
    else:
        break

print(i)

Submission status: Accepted

Solution code:
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N))
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            count = 0
            if a > max(useList):
                while not max(useList) > int(result[-1]):
                    count += 1
                    result = result[:-1]
                    if result == '':
                        break
                if result == '':
                    if useList[0] != 0:
                        result += str(useList[0])
                    else:
                        result += str(useList[1])
                    result += str(useList[0])*(len(N))
                    break
                count += 1
                sect = int(result[-1])
                result = result[:-1]
                result += str(useList[bisect.bisect_right(useList, sect)])
                result += str(useList[0])*(len(N)-len(result))
            else:
                result += str(useList[bisect.bisect_right(useList, a)])
                result += str(useList[0])*(len(N)-i-1)
            break
print(result)

Submission status: Accepted

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

for i in range(n,10*n):
    ans = str(i)
    for j in range(len(ans)):
        if int(ans[j]) in d:
            break

        if j == len(ans) - 1:
            print(i)
            exit()

Submission status: Accepted

Solution code:
n=int(input().split()[0]);a=set(input())
while a&set(str(n)):n+=1
print(n)

Submission status: Accepted

Solution code:
n,_=input().split();s=set(list(input()));n=int(n);print(n+[len(s&set(str(b)))for b in range(n,99999)].index(0))

Submission status: Accepted

Solution code:
n,k,*a=open(0).read().split();n=int(n)
while any(s in set(a)for s in str(n)):n+=1
print(n)

Submission status: Accepted

Solution code:
x=lambda:input().split()
n,_=x();a=x();n=int(n)
while any(s in set(a)for s in str(n)):n+=1
print(n)

Submission status: Accepted

Solution code:
s=set(range(10))
n,k,*a=map(int,open(0).read().split())
a=s-set(a) #使っていい数字
for t in range(n,100000):
    if set(list(map(int,list(str(t)))))<=a:
        print(t)
        break

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main():
	n, k = map(int, input().split())
	lst = list(input().split())
	for i in range(n, 1000000):
		flg = True
		for j in str(i):
			if j in lst:
				flg = False
		if flg:
			print(i)
			return

main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
kazu=[9,8,7,6,5,4,3,2,1,0]
for item in D:
  kazu.remove(item)
p=[]
m=len(str(N))
for i in range(m):
  p.append(kazu[0]*(10**i))
p.sort(reverse=True)
j=0
while j<m:
  for i in range(1,len(kazu)):
    if sum(p)-p[j]+kazu[i]*(10**(m-j-1))>=N:
      p[j]=kazu[i]*(10**(m-j-1))
    else:
      break
  j+=1
if sum(p)<N:
  if kazu[-1]!=0:
    ans=0
    for i in range(m+1):
      ans+=kazu[-1]*(10**i)
  else:
    ans=kazu[-2]*(10)**m
else:
  ans=sum(p)
print(ans)

Submission status: Accepted

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

for ans in range(n, 100000):
    if len(set(str(ans)) & ds) == 0:
        break

print(ans)

Submission status: Accepted

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

for i in range(N,100000):
        ans=True
        for j in str(i):
                if(str(j) in D):
                        ans=False
                        break
        if(ans):
                print(i)
                exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=input().split()
D=list(input().split())
ans=int(N)
while True:
    if set(str(ans))&set(D)==set():
        break
    else:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
L = input().split()
M = N-1
d = 0
flag = True
while flag:
  d = 0
  M += 1
  for j in range(K):
    if L[j] in str(M):
      break
    else:
      d += 1
  if d == K:
    flag = False    
print(M)

Submission status: Accepted

Solution code:
N, _ = input().split()
dislike = list(input().split())

while any(v in N for v in dislike):
    N = str(int(N)+1)
print(N)

Submission status: Accepted

Solution code:
N, _ = input().split()
dislike = list(input().split())

tmp = N
while True:
    if any(v in tmp for v in dislike):
        tmp = str(int(tmp)+1)
    else:
        print(tmp)
        break

Submission status: Accepted

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

def ketajudge(x):
  while x != 0:
    if x%10 in d:
      return False
      break
    else:
      if x//10 == 0:
       return True
       break
    x = x//10 
  
  

for i in range(10*n):
  judge = n+i
  if ketajudge(judge) == True:
    print(judge)
    break

Submission status: Accepted

Solution code:
N, K = input().strip().split()
Ds = set(input().strip().split())

price = N
roop_flag = True
while(roop_flag):
    roop_flag = False
    for d in Ds:
        if(d in price):
            price = str(int(price) + 1)
            roop_flag = True
            break
print(price)

Submission status: Accepted

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

dr=len(d)
for i in range(N,100000):
    s=list(str(i))
    num=0
    for j in d:
        if(str(j) in s):
            break
        else:
            num+=1
    if(num==dr):
        print(i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(str,input().split()))
ans = n
tmp=0
while tmp==0:
    ans_str=str(ans)
    t=0
    for i in range(len(ans_str)):
        for j in range(len(a)):
            if ans_str[i] == a[j]:
                t=1
                break
    if t == 0:
        print(ans_str)
        tmp=1
    ans+=1

Submission status: Accepted

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

while 1:
    n = list(str(N))
    for i in range(len(n)):
        if int(n[i]) in D:
            N += 1
            break
    else:
        print(N)
        break

Submission status: Accepted

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

for ans in range(n, int(1e7)):
  if len(set(str(ans)) & d) == 0:
    print(ans)
    break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
x = list(map(int,input().split()))
t = 1
s = n
f=0
while t:
    for i in range(k):
        f = 0
        if str(x[i]) in str(s):
            break
        elif i == k -1:t = 0
    s+=1
print(s-1)

Submission status: Accepted

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

def f(x):
    c = int(math.log10(x))
    t = []
    for i in range(c+1):
        if x//((10**(c-i)))%10 in d:
            return False
    return True

while not f(res):
    res += 1
print(res)

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())
for i in range(n,10*n):
    si = str(i)
    flag = True
    for j in range(len(si)):
        if int(si[j]) in d:
            flag = False
            break
    if flag:
        print(si)
        break

Submission status: Accepted

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

while True:
    E = set(str(N))
    if len(D & E) == 0:
        print(N)
        break
    N += 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dislike = set(input().split())
while True:
    if all(ch not in dislike for ch in str(n)) is True:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
#C - こだわり者いろはちゃん 2
def checkDigit(n):
    d = []
    for i in range(9):
        if n%10 in D: return False
        n //= 10
        if n==0: return True

def solve(n):
    for i in range(N,1000000):
        if checkDigit(i): return i

N, K = [int(x) for x in input().split()]
D = [int(x) for x in input().split()]
#print(N,K,D)
print(solve(N))

Submission status: Accepted

Solution code:
N, K = map(int, input().split(' '))
D = input().split(' ')
for i in range(N, 10*N+1):
    flag = True
    ans = str(i)
    for n in ans:
        if n in D:
            flag = False
    if flag:
        print(ans)
        exit()

Submission status: Accepted

Solution code:
import itertools

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

c = float("inf")
for i in range(1, 6):
	for x in itertools.product(D, repeat = i):
		z = list(x)
		while True:
			if z[0] == "0" and len(z) >= 2:
				z = z.pop(0)
			else:
				break

		y = int("".join(z))
		if N <= y and y < c:
			c = y

print(c)

Submission status: Accepted

Solution code:
N=int(input().split()[0])
D=[i for i in input().split()]
for i in range(N,100000):
  flag=0
  for d in D:
    for k in range(len(str(i))):
      if str(i)[k]==d:
        flag=1
      if flag==1:
        break
    if flag==1:
      break
  if flag==0:
    break
print(i)

Submission status: Accepted

Solution code:
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
while True:
    count = 0
    br = list(str(a))
    for r in br:
        if int(r) in ar:
            count += 1
    if count == 0:
        print(a)
        break
    else:
        a += 1

Submission status: Accepted

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

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

res = N
while True:
    t = str(res)
    flg = True
    for i in D:
        if not flg:
            break
        for x in t:
            if i == x:
                flg = False
                break

    if flg :
        break
    res += 1
print(res)

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
N, K = inpl()
D = inpl()
for i in range(1000000):
    sn = list(map(int, str(N+i)))
    for s in sn:
        if s in D:
            break
    else:
        print(N+i)
        break

Submission status: Accepted

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

for i in range(0, 10):
    if i in D:
        D.remove(i)
    else:
        D.append(i)

digit = len(N)
con = ''

for i in range(digit):
    if int(N[i]) in D:
        con += N[i]

    else:
        flag = True
        for j in D:
            if j > int(N[i]):
                N = con + str(j) + str(D[0]) * (digit-len(con)-1)
                flag = False
                break

        if flag:
            if D[0] == 0:
                N = str(D[1]) + str(D[0]) * digit
            else:
                N = str(D[0]) * (digit+1)

        break

print(N)

Submission status: Accepted

Solution code:
def ceil(n, i):
    dec = 10 ** i
    return n // 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)
i = 1
while len(str(n)) >= i:
    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 = ceil(n, i) + 10 ** i
        n += int(str(l[0]) * i)
    i += 1
print(n)

Submission status: Accepted

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,100001):
    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: Accepted

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

Submission status: Accepted

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



while True:
    fl=True
    for j in range(len(str(N))):
        for i in range(K):
            if str(N)[j]==str(D[i]):
                fl=False
                break
        if fl==False:
            break
    if fl:
        break
    N+=1

print(N)

Submission status: Accepted

Solution code:

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

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

for i in range(N,100000):
    if len(set(list(str(i)))&set(D))==0:
        print(i)
        break

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
d = input().split()
while True:
  cand = N
  candstring = str(cand)
  ng = False
  for chr in candstring:
    if chr in d:
      ng = True
      break
  if ng:
    N+=1
  else:
    print(cand)
    break

Submission status: Accepted

Solution code:
def not_in_D(N, D):
    for i in range(100000):
        N_list = list(str(N+i))
        N_list = [int(n) for n in N_list]
        can = True
        for n in N_list:
            if n in D:
                can = False
        if can == True:
            print(N + i)
            break
def main():
    N ,K = map(int, input().split())
    D = list(map(int, input().split()))
    not_in_D(N, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(str,input().split()))
for i in range(N,100000):
    cnt=0
    for j in range(len(D)):
        if D[j] not in str(i):
            cnt+=1
    if cnt==len(D):
        print(i)
        exit()

Submission status: Accepted

Solution code:
import itertools
n, k=map(int, raw_input().split())
d=raw_input().split()
for i in itertools.count(n):
	if not any([digit in str(i) for digit in d]):
		print i
		exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(map(int, input().split()))
for i in range(N, N * 10):
    j = i
    while j:
        q = j % 10
        j //= 10
        if q in D:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
s=input().split()
n=int(s[0])
s=input().split()
l=[int(i) for i in s]
for i in range(n,n+100000):
  flag=True
  k=i
  while i>0:
    j=i%10
    if j in l:
      flag=False
      break
    i//=10
  if flag:
    print(k)
    break

Submission status: Accepted

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(100001):
    if i >= N :
        if dig_check(i,d):
            print(i)
            break

Submission status: Accepted

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

while True:
    m = list(str(N))
    f = 0
    for i in d:
        if str(i) in m:
            f += 1
    if f == 0:
        print(N)
        break
    N += 1

Submission status: Accepted

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

while True:
    s = str(n)
    oks = map(lambda d: d not in s, ds)
    if all(oks):
        break
    n += 1

print(n)

Submission status: Accepted

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

line = input().split(" ")
n = int(line[0])
k = int(line[1])
d = set(input().split(" "))

while True:
    s = set(list(str(n)))
    r = s - d
    if len(r)==len(s):
        print(n)
        exit()
    n += 1

Submission status: Accepted

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

for ans in range(N, 88889):
    As = set(str(ans))
    if not (Ds & As):
        break

print(ans)

Submission status: Accepted

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
    if flag==0:
        break
print(ans)

Submission status: Accepted

Solution code:
k, n = (int(x) for x in raw_input().split())
d = raw_input().split()
while True:
	good = True
	for x in str(k):
		if x in d:
			good = False
			break
	if good:
		break
	k += 1
print k

Submission status: Accepted

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

def main():
    n, k = map(int, input().split())
    dk = list(map(int, input().split()))
    assert len(dk) == k

    us = set(usable(dk))
    print(form(us, n))

def form(us, n):
    for res in range(n, 10 ** 5):
        fla = True
        for c in str(res):
            if int(c) not in us:
                fla = False
                break
        if fla:
            return res
    raise Exception

def usable(dk):
    res = []
    for i in range(10):
        if i not in dk:
            res.append(i)
    return res

main()

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
a = set(raw_input().split())
while set(str(n)) & a:
	n += 1
print n

Submission status: Accepted

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


count = N

while True:
    flag = True
    for i in D:
        if str(i) in str(count):
            count += 1
            flag = False
    if flag:
        break
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

for m in range(n, 10*n) :
    s = str(m)
    for dk in d :
        if dk in s :
            break
    else :
        print(m)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

ans = N
while True:
    for c in str(ans):
        if c in ds:
            ans += 1
            break
    else:
        break
print(ans)

Submission status: Accepted

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

a = list(map(str,input().split()))
ans = 0
b = 0
for i in range(n,100001):
    for j in str(i):
        if not j in a:
            b += 1
    if b == len(str(i)):
        ans = i
        break
    else:
        b = 0
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
n,k=map(int,input().split())
d=input().split()
while True:
    for c in d:
        if c in str(n):
            break
    else:
        print(n)
        break
    n+=1

Submission status: Accepted

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


def is_kirai(n, D):
    if n == 0:
        if 0 in D:
            return True
    while n:
        if n % 10 in D:
            return True
        else:
            n = n // 10

    return False


n = N
while True:
    if not is_kirai(n, D):
        print(n)
        quit()
    else:
        n += 1

Submission status: Accepted

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


def main():
    N, K = input().split(' ')
    D = set(map(int, input().split(' ')))
    can_use_num = set(map(str, set(range(10)) - D))

    n = int(N)
    while True:
        if set(str(n)) <= can_use_num:
            break
        n += 1
    print(n)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#品物の金額
n = arr_data[0][0]

#嫌いな数字の数
k = int(arr_data[0][1])

#arr=list(map(int, arr_data[1]))
arr=arr_data[1]

#print(n,k,arr)

chkflg=True

while chkflg:
    
    for v in n:
        
        if v in arr:
            
            n = str(int(n)+1) 
            break
            
    else:
        
        chkflg=False
        
print(n)
#
#for v in n:
#    
##    print(v)
##    print(v,v in arr)
#    
#    if v in arr:
#        
#        n = str(int(n)+1)
#        
#    else:
#

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
while True:
    m=n
    f=False
    while m>0:
        if m%10 in d:
            f=True
            break
        m=int(m/10)
    if f:
        n+=1
    else:
        print(n)
        break

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(index+1,len(N)):
	N[i] = mv
print(''.join(N))

Submission status: Accepted

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
        if i==len(str(n))-1:
            print(n)
            exit()
    n+=1

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lis = list(map(str,input().split()))
while 1:
    for i in range(len(str(n))):
        if str(n)[i] in lis:
            break
        if i == len(str(n))-1:
            print(n)
            exit()
    n += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=set(input().split())
a=[]
for i in range(n,10*n):
    if not set(str(i))&set(d):
        print(i)
        exit()

Submission status: Accepted

Solution code:
n, k = map(int,raw_input().split())
s = set(raw_input().split())
for i in range(n,100000):
	if len(s - set(list(str(i)))) == k:
		print i
		break

Submission status: Accepted

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

while True:
    flag=False
    for i in range(len(str(n))):
        if int(str(n)[i]) in d:
            flag=True
            break
    if flag==True:
        n+=1
    else:
        print(n)
        break

Submission status: Accepted

Solution code:
#T = int(rw_input())
T = 1

def check(n, D):
    a = map(lambda x : ord(x) - ord('0'), str(n))
    for i in a:
        if i in D:
            return False
    return True


def get(n, D):
    while True:
        if check(n, D):
            return n
        n += 1
    return n

for i in range(T):
    n, k = map(int, raw_input().split())
    D = map(int, raw_input().split())
    D = set(D)
    print get(n, D)