Buggy python submission (verdict: Time Limit Exceeded):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
n=l[0]
n_list=list(int(j) for j in str(n))  
while True:
    n_set=set(n_list)
    if n_set<=d_bar:
        print(n)
    else:
        n=n+1
    

Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Time Limit Exceeded):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
N=l[0]
K=l[1]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(N)]
dig1=''
dig2=0
for i in range(len(n)):
    for j in range(len(d_bar)):
        p=dig1+str(d_bar[j])
        if int(p)>l[0]:
            dig2=dig2*K**i+int(dig1)
            break
        dig1=p
        
dig2=dig2+1
r=dig2
q=dig2
R=[]
while q!=0 or q!=1:
    q=q//K
    r=q%K
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))




Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Time Limit Exceeded):
l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=''
    dig2=0
    for j in range(l[1]):
        p=dig1.join(str(d_bar[j]))
        if int(p)>l[0]:
          dig2=dig2+int(dig1)*l[1]**(l[0]-i)
          break
        dig1=p     
dig2=dig2+1
r=int(dig1)
q=int(dig1)
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))




Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Time Limit Exceeded):
l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=''
    dig2=0
    for j in range(l[1]):
        p=dig1.join(str(d_bar[j]))
        if int(p)>l[0]:
          break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(l[0]-i)
dig2=dig2+1
r=int(dig1)
q=int(dig1)
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))




Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Time Limit Exceeded):
l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=0
    dig2=0
    for j in range(l[1]):
        p=dig1+d_bar[j]*10**(l[0]-i)
        if p>l[0]:
            break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(l[0]-i)
dig2=dig2+1
r=dig1
q=dig1
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=0
for t in range(len(R)):
    s=s+R[t]*10**(t)
print(s)




Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])

for i in range(len(n))
    dig1=0
    dig2=0
    for j in range(l[1]):
        p=dig1+d_bar[j]*10**(range(l[0])-i)
        if p>l[0]:
            break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(range(l[0])-i)
dig2=dig2+1
r=dig
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.append(r)
s=int(sum[str(-t-1) for t in R])
print(s)




Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
a=[]
p=0
n_int=[int(k) for k in str(l[0])]
for i in range(len(n_int)):
    a.append(10)
    for j in range(len(d_bar)):
        if n_int[-i-1]==d_bar[j]:
            a.pop(i)
            a.append(d_bar[j+p])
            p=0
            break
        elif n_int[-i-1]<d_bar[j]:
            a.pop(i)
            a.append(d_bar[j])
            p=0
            break
    if a[i]==10:
        a.pop(i)
        a.append(d_bar[0])
        p=1
b=''
for q in range(len(n_int)):
    b=b+str(a[-q-1]) 
print(int(b))

Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
a=[]
n_str=str(l[0])
n_int=[int(k) for k in n_str]
for i in n_int:
    a.append('na')
    for j in d_bar:
        if i<=j:
            a[i-1]=j
            break
        else:
            pass
    if a[i-1]='na':
        a[i-1]=d_bar[0]
if a[0]=0:
    a.insert(0,d_bar[0])

print(int(a))

Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
a=''
for i in str(l[0]):
    for j in d_bar:
        if int(i)<=j:
            k=str(j)
            break
        else:
            pass
    a=a+k
print(int(a))

Fixed submission:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))