Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i += a:
    i += 1
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a + 1:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a + 1:
    i += 1
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        i = 0
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 1
while 1:
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        i = 0
    i += 1
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
    if i == a + 1:
        break
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 1
while 1:
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        i = 0
    i += 1
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
    if i == a:
        break
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = (n[0] % 10000) // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    f = n[0] // 10000
    
    if np.any(d == f):
        n[0] = f * 10000
    elif np.any(d == a):
        n[0] = f * 10000 + (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = a * 1000 + (b + 1) * 100
    elif np.any(d == c):
        n[0] = a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = n[0] // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    
    if np.any(d == a):
        n[0] = (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = a * 1000 + b * 100
    elif np.any(d == c):
        n[0] = a * 1000 + b * 100 + c * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Fixed submission:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))