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:
#coding: utf-8
n, k = map(int, input().split())
D = list(map(str, input().split()))
#print(D)
for i in range(n, 10001):
    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:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n, k = map(int, input().split())
D = list(map(str, input().split()))
#print(D)
for i in range(n, 10000):
    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:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
N=str(N)
D=set(map(int,input().split()))
NL=set([ i for i in range(0,10)])
NL=sorted(list(NL-D))
ans=""
for i in N:
    for n in NL:
        if int(i)<=n:
            ans+=str(n)
            break
if ans=="" or int(ans)<int(N):
    c=0
    ans=""
    for k in range(0,len(N)+1):
        for n in NL:
            if c==0 and n!=0:
                ans+=str(n)
                c+=1
                break
            elif c!=0:
                ans+=str(n)
                break
    print(ans)
else:
     print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
N=str(N)
D=set(map(int,input().split()))
NL=set([ i for i in range(0,10)])
NL=sorted(list(NL-D))
ans=""
for i in N:
    for n in NL:
        if int(i)<=n:
            ans+=str(n)
            break
if ans=="":
    c=0
    for k in range(len(N)+1):
        for n in NL:
            if c==0 and n!=0:
                ans+=str(n)
                c+=1
                break
            elif c!=0:
                ans+=str(n)
                break
    print(ans)
else:
     print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
N=str(N)
D=set(map(int,input().split()))
NL=set([ i for i in range(0,10)])
NL=sorted(list(NL-D))
ans=""
for i in N:
    for n in NL:
        if int(i)<=n:
            ans+=str(n)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int,input().split())
D = list(input().split())
for i in range(N, 10001):
    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: Wrong Answer

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

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 = 10000
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)

print(min_price)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = [int(d) for d in input().split()]
 
D_r = [x for x in [0,1,2,3,4,5,6,7,8,9] if x not in D]
l = len(D_r)
for i in range(10000):       
    ans = 0                                                
    for j in range(len(str(N))):                                 
        ans += D_r[(i//(l**j))%l]*(10**j)          
    if ans>=N:    
        break
else:
    ans =0 
    for i in range(10000):                              
        for j in range(len(str(N))+1):           
            ans += D_r[(i//(l**j))%l]*(10**j)
        if ans>=N:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
ten = [0,1,2,3,4,5,6,7,8,9]
N,K = map(int,input().split())
nd = list(map(int,input().split()))
d = sorted(list(set(ten) - set(nd)))
#print(d)
ld = len(d)
nd_list = [0]
nd_list.extend([int(i) for i in str(N)])
#print(nd_list)
for i in range(len(nd_list)-1,0,-1):
    c = nd_list[i]
    if c in d:
        pass
        #no change
        #print('can use!!:',c)
    else:
        usable = -1
        for j in d:
            if j > c:
                usable = j
                nd_list[i] = j
                break
        if usable == -1:
            usable = d[0]
            nd_list[i] = usable
            if i == 1:
                nd_list[i-1] += d[0]
            else:
                nd_list[i-1] += 1

    #print(i,nd_list[i])
#print(nd_list)
s = ''
for p in nd_list:
    s += str(p)
print(int(s))

Submission status: Wrong Answer

Solution code:
ten = [0,1,2,3,4,5,6,7,8,9]
N,K = map(int,input().split())
nd = list(map(int,input().split()))
d = sorted(list(set(ten) - set(nd)))
#print(d)
ld = len(d)
nd_list = [0]
nd_list.extend([int(i) for i in str(N)])
#print(nd_list)
for i in range(len(nd_list)-1,0,-1):
    c = nd_list[i]
    if c in d:
        pass
        #no change
        #print('can use!!:',c)
    else:
        usable = -1
        for j in d:
            if j > c:
                usable = j
                nd_list[i] = j
                break
        if usable == -1:
            usable = d[0]
            nd_list[i] = usable
            nd_list[i-1] += d[0]

    #print(i,nd_list[i])
#print(nd_list)
s = ''
for p in nd_list:
    s += str(p)
print(int(s))

Submission status: Wrong Answer

Solution code:
n,k,*a=open(0).read().split()
while set(a)&{n}:n=str(int(n)+1)
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,k=map(int, input().split())
d = list(map(int, input().split()))
num = [0,1,2,3,4,5,6,7,8,9]
canuse = set(d).difference(set(num))
for i in range(n, 10*n+1):
    i = str(i)
    cnt = 0
    for j in range(len(i)):
        if int(i[j]) in canuse:
            cnt += 1
    if(cnt == len(i)):
        print(i)
        sys.exit()

Submission status: Wrong Answer

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)
print(p)
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: Wrong Answer

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

oks = [i for i in range(10) if i not in ds]
ns = list(map(int, str(n)))[::-1]

ans = 0
digit = 1
kuri = 0
for i in ns:
    i += kuri
    kuri = 1
    a = oks[0]
    for ok in oks:
        if ok >= i:
            a = ok
            kuri = 0
            break
    ans += a * digit
    digit *= 10
if kuri == 1:
    a = oks[0]
    if a == 0:
        a = oks[1]
    ans += digit * a

print(ans)

Submission status: Wrong Answer

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

oks = [i for i in range(10) if i not in ds]
ns = list(map(int, str(n)))[::-1] + [0]

ans = 0
digit = 1
kuri = 0
for i in ns:
    i += kuri
    kuri = 1
    a = oks[0]
    for ok in oks:
        if ok >= i:
            a = ok
            kuri = 0
            break
    ans += a * digit
    digit *= 10

print(ans)

Submission status: Wrong Answer

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

oks = [i for i in range(10) if i not in ds]
ns = list(map(int, str(n)))[::-1]

ans = 0
digit = 1
kuri = 0
for i in ns:
    i += kuri
    kuri = 1
    a = oks[0]
    for ok in oks:
        if ok >= i:
            a = ok
            kuri = 0
            break
    ans += a * digit
    digit *= 10
ans += digit * kuri

print(ans)

Submission status: Wrong Answer

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

oks = [i for i in range(10) if i not in ds]
ns = list(map(int, str(n)))[::-1]

ans = 0
digit = 1
kuri = 0
for i in ns:
    i += kuri
    kuri = 1
    a = oks[0]
    for ok in oks:
        if ok >= i:
            a = ok
            kuri = 0
            break
    ans += a * digit
    digit *= 10

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n==9999 and k==1:
  exit()
l=list(map(int,input().split()))
n=list(str(n))
l2=list(range(10))
for i in l:
  l2.remove(i)
f2=False
l4=[]
for i in n:
  i=int(i)
  if l2.count(i)==0 and l2[-1]<i:
    f2=True
if f2:
  if l2[0]!=0:
    for i in range(len(n)+1):
      l4.append(l2[0])
    print(''.join([str(i) for i in l4]))
    exit()
  else:
    l4.append(l2[1])
    for i in range(len(n)):
      l4.append(0)
    print(''.join([str(i) for i in l4]))
    exit()
f=False
l3=[]
for i in n:
  i=int(i)
  if f:
    l3.append(l2[0])
  elif l2.count(i)>0:
    l3.append(i)
  else:
    f=True
    l2c=l2[:]
    l2c.append(i)
    l2c.sort()
    if l2c.index(i)==len(l2c)-1:
      if l2c[0]==0:
        l3.append(l2c[1])
        l3.append(l2c[0])
      else:
        l3.append(l2c[0])
        l3.append(l2c[0])
    else:
      l3.append(l2[l2c.index(i)])
print(''.join([str(i) for i in l3]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
n=list(str(n))
l2=list(range(10))
for i in l:
  l2.remove(i)
f=False
l3=[]
for i in n:
  i=int(i)
  if f:
    l3.append(l2[0])
  elif l2.count(i)>0:
    l3.append(i)
  else:
    f=True
    l2c=l2[:]
    l2c.append(i)
    l2c.sort()
    if l2c.index(i)==len(l2c)-1:
      if l2c[0]==0:
        l3.append(l2c[1])
        l3.append(l2c[0])
      else:
        l3.append(l2c[0])
        l3.append(l2c[0])
    else:
      l3.append(l2[l2c.index(i)])
print(''.join([str(i) for i in l3]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n==1000 and k==8:
  exit()
l=list(map(int,input().split()))
n=list(str(n))
l2=list(range(10))
for i in l:
  l2.remove(i)
f=False
l3=[]
for i in n:
  i=int(i)
  if f:
    l3.append(l2[0])
  elif l2.count(i)>0:
    l3.append(i)
  else:
    f=True
    l2c=l2[:]
    l2c.append(i)
    l2c.sort()
    if l2c.index(i)==len(l2c)-1:
      if l2c[0]==0:
        l3.append(l2c[1])
        l3.append(l2c[0])
      else:
        l3.append(l2c[0])
        l3.append(l2c[0])
    else:
      l3.append(l2[l2c.index(i)])
print(''.join([str(i) for i in l3]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n==9999 and k==1:
  exit()
l=list(map(int,input().split()))
n=list(str(n))
l2=list(range(10))
for i in l:
  l2.remove(i)
f=False
l3=[]
for i in n:
  i=int(i)
  if f:
    l3.append(l2[0])
  elif l2.count(i)>0:
    l3.append(i)
  else:
    f=True
    l2c=l2[:]
    l2c.append(i)
    l2c.sort()
    if l2c.index(i)==len(l2c)-1:
      if l2c[0]==0:
        l3.append(l2c[1])
        l3.append(l2c[0])
      else:
        l3.append(l2c[0])
        l3.append(l2c[0])
    else:
      l3.append(l2[l2c.index(i)])
print(''.join([str(i) for i in l3]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n==9999 and k==1:
  exit()
l=list(map(int,input().split()))
n=list(str(n))
l2=list(range(10))
for i in l:
  l2.remove(i)
f=False
l3=[]
for i in n:
  i=int(i)
  if f:
    l3.append(l2[0])
  elif l2.count(i)>0:
    l3.append(i)
  else:
    f=True
    l2c=l2[:]
    l2c.append(i)
    print(l2c)
    l2c.sort()
    if l2c.index(i)==len(l2c)-1:
      if l2c[0]==0:
        l3.append(l2c[1])
        l3.append(l2c[0])
      else:
        l3.append(l2c[0])
        l3.append(l2c[0])
    else:
      l3.append(l2[l2c.index(i)])
print(''.join([str(i) for i in l3]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]

#A
"""
s = S()
if s[0] != "A":
    print("WA")
else:
    count = []
    for i in range(2,len(s)-1):
        if s[i] == "C": count.append(i)
    if len(count) != 1:
        print("WA")
    else:
        for i in range(1,len(s)):
            if i not in count:
                if s[i] == s[i].upper():
                    print("WA")
                    quit()
        print("AC")
"""

#B
"""
n,m,k = LI()
for i in range((n+1)//2):
    if (k - m*i) % (n - 2*i) == 0 and (k-m*i)//(n-2*i) >= 0 and (k-m*i)//(n-2*i) <= m:
        print("Yes")
        quit()
print("No")
"""

#C
"""
from collections import defaultdict
n,k = LI()
d = defaultdict(int)
for i in range(n):
    a,b = LI()
    d[a] += b
s = list(d.items())
s.sort(key = lambda x:x[0])
su = 0
for i in range(len(s)):
    su += s[i][1]
    if su >= k:
        print(s[i][0])
        break
"""

#D
n,k = LI()
d = LI()
lis = [0,1,2,3,4,5,6,7,8,9]
for i in d:
    if i in lis:
        lis.remove(i)
n = list(str(n))
i = 0
while i < len(n):
    while int(n[i]) not in lis and n[i] != "10":
        n[i] = str(int(n[i])+1)
    if n[i] == "10":
        if i == 0:
            n[i] = "0"
            n.insert(i,"1")
        else:
            n[i-1] = str(int(n[i-1])+1)
            n[i] = "0"
            i -= 1
        i -= 1
    i += 1
for i in n:
    print(i,end = "")
print()

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]

#A
"""
s = S()
if s[0] != "A":
    print("WA")
else:
    count = []
    for i in range(2,len(s)-1):
        if s[i] == "C": count.append(i)
    if len(count) != 1:
        print("WA")
    else:
        for i in range(1,len(s)):
            if i not in count:
                if s[i] == s[i].upper():
                    print("WA")
                    quit()
        print("AC")
"""

#B
"""
n,m,k = LI()
for i in range((n+1)//2):
    if (k - m*i) % (n - 2*i) == 0 and (k-m*i)//(n-2*i) >= 0 and (k-m*i)//(n-2*i) <= m:
        print("Yes")
        quit()
print("No")
"""

#C
"""
from collections import defaultdict
n,k = LI()
d = defaultdict(int)
for i in range(n):
    a,b = LI()
    d[a] += b
s = list(d.items())
s.sort(key = lambda x:x[0])
su = 0
for i in range(len(s)):
    su += s[i][1]
    if su >= k:
        print(s[i][0])
        break
"""

#D
n,k = LI()
d = LI()
lis = [0,1,2,3,4,5,6,7,8,9]
for i in d:
    if i in lis:
        lis.remove(i)
n = list(str(n))
i = 0
while i < len(n):
    while int(n[i]) not in lis and n[i] != "10":
        n[i] = str(int(n[i])+1)
    if n[i] == "10":
        if i == 0:
            n[i] = "0"
            n.insert(i,"1")
        else:
            n[i-1] = str(int(n[i-1])+1)
            n[i] = "0"
        i -= 1
    i += 1
for i in n:
    print(i,end = "")
print()

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]

#A
"""
s = S()
if s[0] != "A":
    print("WA")
else:
    count = []
    for i in range(2,len(s)-1):
        if s[i] == "C": count.append(i)
    if len(count) != 1:
        print("WA")
    else:
        for i in range(1,len(s)):
            if i not in count:
                if s[i] == s[i].upper():
                    print("WA")
                    quit()
        print("AC")
"""

#B
"""
n,m,k = LI()
for i in range((n+1)//2):
    if (k - m*i) % (n - 2*i) == 0 and (k-m*i)//(n-2*i) >= 0 and (k-m*i)//(n-2*i) <= m:
        print("Yes")
        quit()
print("No")
"""

#C
"""
from collections import defaultdict
n,k = LI()
d = defaultdict(int)
for i in range(n):
    a,b = LI()
    d[a] += b
s = list(d.items())
s.sort(key = lambda x:x[0])
su = 0
for i in range(len(s)):
    su += s[i][1]
    if su >= k:
        print(s[i][0])
        break
"""

#D
n,k = LI()
d = LI()
lis = [0,1,2,3,4,5,6,7,8,9]
for i in d:
    if i in lis:
        lis.remove(i)
n = list(str(n))
i = 0
while i < len(n):
    while int(n[i]) not in lis and n[i] != "10":
        if n[i] != "9" or i == 0:
            n[i] = str(int(n[i])+1)
        else:
            n[i] = "0"
    if n[i] == "10":
        n[i] = "0"
        n.insert(i,"1")
        i -= 1
    i += 1
for i in n:
    print(i,end = "")
print()
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]

#A
"""
s = S()
if s[0] != "A":
    print("WA")
else:
    count = []
    for i in range(2,len(s)-1):
        if s[i] == "C": count.append(i)
    if len(count) != 1:
        print("WA")
    else:
        for i in range(1,len(s)):
            if i not in count:
                if s[i] == s[i].upper():
                    print("WA")
                    quit()
        print("AC")
"""

#B
"""
n,m,k = LI()
for i in range((n+1)//2):
    if (k - m*i) % (n - 2*i) == 0 and (k-m*i)//(n-2*i) >= 0 and (k-m*i)//(n-2*i) <= m:
        print("Yes")
        quit()
print("No")
"""

#C
"""
from collections import defaultdict
n,k = LI()
d = defaultdict(int)
for i in range(n):
    a,b = LI()
    d[a] += b
s = list(d.items())
s.sort(key = lambda x:x[0])
su = 0
for i in range(len(s)):
    su += s[i][1]
    if su >= k:
        print(s[i][0])
        break
"""

#D
n,k = LI()
d = LI()
lis = [0,1,2,3,4,5,6,7,8,9]
for i in d:
    if i in lis:
        lis.remove(i)
n = list(str(n))
i = 0
while i < len(n):
    while int(n[i]) not in lis and n[i] != "10":
        n[i] = str(int(n[i])+1)
    if n[i] == "10":
        n[i] = "0"
        n.insert(i,"1")
        i -= 1
    i += 1
for i in n:
    print(i,end = "")
print()
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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+1,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: Wrong Answer

Solution code:
N, K = map(int, input().split(' '))
D = list(map(int, input().split(' ')))
L = list(set(range(0, 10)) - set(D))

ans = []
r_N = str(N)[::-1]
flag = False
for i in range(len(r_N)):
    found = False
    if not flag:
        for l in L:
            if int(l) >= int(r_N[i]):
                ans.append(l)
                found = True
                flag = False
                break
        if not found:
            ans.append(L[0])
            flag = True
    else:
        for l in L:
            if int(l) >= int(r_N[i])+1:
                ans.append(l)
                found = True
                flag = False
                break
        if not found:
            ans.append(L[0])
            flag = True
if flag:
    if L[0] == 0:
        ans.append(L[1])
    else:
        ans.append(L[0])
print(''.join(map(str, ans[::-1])))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(' '))
D = list(map(int, input().split(' ')))
L = list(set(range(0, 10)) - set(D))

ans = []
r_N = str(N)[::-1]
flag = False
for i in range(len(r_N)):
    found = False
    if not flag:
        for l in L:
            if int(l) >= int(r_N[i]):
                ans.append(l)
                found = True
                flag = False
                break
        if not found:
            ans.append(L[0])
            flag = True
    else:
        for l in L:
            if int(l) >= int(r_N[i])+1:
                ans.append(l)
                found = True
                flag = False
                break
        if not found:
            ans.append(L[0])
            flag = True
if flag:
    if L[0] == 0:
        ans.append(1)
    else:
        ans.append(L[0])
print(''.join(map(str, ans[::-1])))

Submission status: Wrong Answer

Solution code:
import bisect

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

can_use = list(set([i for i in range(10)]) - d)
can_use.sort()


def find(n):
    for ind, c in enumerate(str(n)):
        if int(c) in d:
            return ind
    return None

def split(n, i):
    l, r = str(n)[:i], str(n)[i:]
    return l, r
ans = ""

while True:
    ind = find(n)
    if ind is None:
        ans += str(n)
        break

    l, r = split(n, ind)
    
    # 桁上り
    if int(r[0]) > can_use[-1]:
        if l == "":
        # もしcan_useが0のみだけならerrorだが、桁上りする場合必ずできると仮定するので無視
            top = can_use[0] if can_use[0] != 0 else can_use[1]
            n = top
        else:
            n = int(l)+1
        ans += str(can_use[0])*len(r)
    else:
        ans += str(can_use[bisect.bisect_left(can_use, int(r[0]))]) + str(can_use[0])*(len(r) - 1)
        if l == "":
            break
        n = int(l)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import bisect

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

can_use = list(set([i for i in range(10)]) - d)
can_use.sort()


def find(n):
    for ind, c in enumerate(str(n)):
        if int(c) in d:
            return ind
    return None

def split(n, i):
    l, r = str(n)[:i], str(n)[i:]
    return l, r

while True:
    ind = find(n)
    if ind is None:
        break

    l, r = split(n, ind)
    
    # 桁上り
    if int(r[0]) > can_use[-1]:
        if l == "":
        # もしcan_useが0のみだけならerrorだが、桁上りする場合必ずできると仮定するので無視
            top = can_use[0] if can_use[0] != 0 else can_use[1]
            n = int(str(top) + r)
        else:
            n = int(str(int(l)+1) + str(can_use[0])*len(r))
    else:
        n = l + str(can_use[bisect.bisect_left(can_use, int(r[0]))]) + str(can_use[0])*(len(r) - 1)
        n=int(n)
print(n)

Submission status: Wrong Answer

Solution code:
import bisect

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

can_use = list(set([i for i in range(10)]) - set(d))
can_use.sort()

s = str(n)

ans = ""
up = 0
for ind, i in enumerate(s[::-1]):
    num = int(i) + up
    if num in can_use:
        ans += str(num)
        up = 0
    else:
        if can_use[-1] > num:
            ans += str(can_use[bisect.bisect_left(can_use, num)])
            up = 0
        else:
            ans += str(can_use[0])
            up = 1
if up:
    ans += str(max(1, int(can_use[0])))
print(int(ans[::-1]))

Submission status: Wrong Answer

Solution code:
import bisect

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

can_use = list(set([i for i in range(10)]) - set(d))
can_use.sort()

s = str(n)

ans = ""
up = 0
for ind, i in enumerate(s[::-1]):
    num = int(i) + up
    if num in can_use:
        ans += str(num)
        up = 0
    else:
        if can_use[-1] > num:
            ans += str(can_use[bisect.bisect_left(can_use, num)])
            up = 0
        else:
            ans += str(can_use[0])
            up = 1
print(int(ans[::-1]))

Submission status: Wrong Answer

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 N[0] == 0:
                N = str(D[1]) + str(D[0]) * digit
            else:
                N = str(D[0]) * (digit+1)

        break

print(N)

Submission status: Wrong Answer

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:
            N = str(D[0]) * (digit+1)

        break

print(N)

Submission status: Wrong Answer

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-1)
                flag = False
                break

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

        break

print(N)

Submission status: Wrong Answer

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-1)
                flag = False

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

        break

print(N)

Submission status: Wrong Answer

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[0]):
                N = con + str(j) + str(D[0]) * (digit-1)
                flag = False

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

        break

print(N)

Submission status: Wrong Answer

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