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

Solution (Python):
from bisect import bisect_left as bl
N, K = map(list, input().split())
D = list(map(int, input().split()))
D = [i for i in range(10) if not i in D]
res = []
big = 0
if int("".join([str(D[-1])] * len(N))) < int("".join(N)):
  if int(K[0]) < 9:
    if D[0] == 0:
      res = [D[1]] + [0] * len(N)
    else:
      res = [D[0]] * (len(N) + 1)
  else:
    res = [D[0]] * (len(N) + 1)
else:
  for i in range(len(N)):
    if big == 0:
      res.append(D[bl(D, int(N[i]))])
    else: res.append(D[0])
    if res[i] > int(N[i]): big = 1
print("".join(list(map(str, res))))

Solution (Python):
n, k = map(int, input().split())
d = tuple(map(str, input().split()))
for i in range(n, 10 ** 9):
    b = True
    for s in tuple(str(i)):
        if s in d:
            b = False
            break
    if b:
        print(i)
        exit()

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

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

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n,k = [int(i) for i in readline().split()]
d = [int(i) for i in readline().split()]

ng = [1 if i in d else 0 for i in range(10)]


for i in range(n,10**6):
    s = str(i)
    for j in s:
        if ng[int(j)]: break
    else:
        print(i)
        break

Solution (Python):


import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
k=hoge[1]

d=[]
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,k):
	d.append(hoge[i])

payment=0
for i in range(0,100000):
	payment=n+i
	for j in range(0,k):
		if(str(d[j]) in str(payment)):
			break
		if(j==k-1):
			print(payment)
			sys.exit()

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

while 1:
    f=0
    s=str(N)
    for i in s:
        if int(i) in D:
            f=1
    if f==0:
        break
    else:
        N+=1
print(N)

Solution (Python):
N, K = map(int,input().split())
U = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
for d in list(map(int,input().split())):
    if d in U:
        U.remove(d)

def check(n):
    for s in str(n):
        if int(s) not in U:
            return False
    if n >= N:
        return True
    else:
        return False

ans = N
while not check(ans):
    ans += 1

print(ans)

Solution (Python):
n, k = map(int, input().split())
d = set(list(map(int, input().split())))
d = list(set([i for i in range(10)])-d)
d.sort()
import itertools

import sys
for k in range(6):
  for i in itertools.product(d, repeat=k):
    ans = 0
    for j in range(len(i)):
      ans += i[-j-1]*10**j
    if ans >= n:
      print(ans)
      sys.exit()

Solution (Python):
import itertools
n,k=map(int,input().split())
l=list(range(10))
l_tmp=list(map(int,input().split()))
for i in l_tmp:
    l.remove(i)
keta=len(str(n))
li=list(itertools.product(l,repeat=keta))
ans=[int("".join(map(str,i))) for i in li]
tmp=[str(min([i for i in l if i>0]))]+[str(min(l))]*keta
ans.append(int("".join(tmp)))
print(min([i for i in ans if i>=n]))

Solution (Python):
N,K=map(int,input().split())
a=set(map(str,input().split()))
for i in range(N,10**5):
    if a&set(str(i))==set():
        print(i)
        break

Solution (Python):



N, K = input().split()
int_N = int(N)
arr = list(input().split())
max_num = pow(10,6)

for i in range(int_N, max_num):
    li = list(set(list(str(i))))
    for j in range(len(li)):
        if li[j] in arr:
            break
    else:
        print(i)
        exit()

Solution (Python):

def main():
    n, k = list(map(int, input().rstrip().split()))
    D = set(map(int, input().rstrip().split()))
    ans = n
    while any(int(i) in D for i in str(ans)):
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,k,*d=map(int,open(0).read().split())
t=set(map(str,set(d)))

for i in range(n,1000000):
    if set(str(i))&t:
        continue
    else:
        print(i)
        break

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N, M = mi()
nos = set(input().split())

availables = sorted(list(set(map(str, (0,1,2,3,4,5,6,7,8,9))) - nos))









ans = 0
for i in range(N, 100000):
  if not (set(str(i)) & nos): 
    ans = i
    break


print(ans)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N, M = mi()
nos = set(input().split())

availables = sorted(list(set(map(str, (0,1,2,3,4,5,6,7,8,9))) - nos))









ans = 0
for i in range(N, 10000):
  if not (set(str(i)) & nos): 
    ans = i
    break
if ans == 0:
  
  if '0' in availables:
    print(str(list(availables)[1])+str(list(availables)[0])*4)
    exit()
  else:
    print(str(list(availables)[0])*5)
    exit()

print(ans)

Solution (Python):
p=input().rstrip().split(' ')
q=input().rstrip().split(' ')
for i in range(int(p[0]),1000000000000):
    t=list(str(i))
    G=0;
    for j in range(0,len(t)):
        if t[j] not in q:
            continue;
        else:
            G=1;
            break;
    if G==0:
        print(i)
        break;

Solution (Python):
N ,K = map(int,input().split())
hate_num = [str(i) for i in map(int,input().split())]

start = N
while True :
    start_list = list(str(start))
    flag = True
    for i in start_list:
        if i in hate_num :
            flag = False
    if flag :
        print(start)
        break
    else :
        start += 1

Solution (Python):
def main():
    n, k = map(int, input().split())
    D = set(input().split())

    numbers = [str(number) for number in range(n, 10 * n)]
    for number in numbers:
        if ok(number, D):
            print(number)
            break


def ok(number, D):
    return len({c for c in number} & D) == 0


main()

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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]
    
    while True:
        n = N
        while True:
            if n % 10 in D:
                N = N + 1
                break
            
            n = int(n / 10)
            if n == 0:
                print(N)
                quit()
c()

Solution (Python):

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

for i in range(n, 100000):
    tmp = list(str(i))
    cnt = 0
    for j in range(len(tmp)): 
        
        if tmp[j] in D:
            cnt += 1
    
    if cnt == 0 and i >= n:
        print(i)
        break

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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")

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

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

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

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

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

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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

Solution (Python):

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

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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)

Solution (Python):


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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):


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

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

Solution (Python):
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)

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

Solution (Python):
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()

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):

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

Solution (Python):
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