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):
n,k=map(int,input().split())

D=set(input().split())

while set(list(str(n)))&D!=set():
    n+=1

print(n)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n, k = ns()
    d = sys.stdin.readline().split()

    s_n = str(n)

    flg = True
    while flg:
        s_n = str(n)

        flg_tmp = True
        for di in d:
            if di in s_n:
                flg_tmp = False
                break

        flg = not flg_tmp
        n += 1

    print(n - 1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    n, k = map(int, readline().split())
    d = {int(i) for i in readline().split()}
    dq = deque()
    dq.append(0)
    cnd = []
    while len(dq)>0:
        v = dq.popleft()
        for i in range(10):
            if i in d:
                continue
            cnd.append(v*10+i)
            dq.append(v*10+i)
        if n <= dq[-1]:
            break

    ans = 0
    for i in cnd:
        if n <= i:
            print(i)
            break
if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    n, k = map(int, readline().split())
    d = {int(i) for i in readline().split()}
    dq = deque()
    cnd = []
    for i in range(10):
        if i in d:
            continue
        dq.append(i)
        cnd.append(i)

    while len(dq)>0:
        v = dq.popleft()
        for i in range(10):
            if i in d:
                continue
            cnd.append(v*10+i)
            dq.append(v*10+i)
        if n <= dq[-1]:
            break

    ans = 0
    for i in cnd:
        if n <= i:
            print(i)
            break
if __name__ == '__main__':
    main()

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

Solution (Python):
n,_,*d=open(0).read().split()
n=int(n)
while 1:
 if all(d not in str(n)for d in d):exit(print(n))
 n+=1

Solution (Python):
n,_,*d=open(0).read().split()
n,d=int(n),set(d)
while 1:
 if not d&set(str(n)):exit(print(n))
 n+=1

Solution (Python):
n,k=input().split()
n=int(n)
d=set(input().split())
while 1:
 if not d&set(str(n)):exit(print(n))
 n+=1

Solution (Python):
n, k, *d = open(0).read().split()
n, d = int(n), set(d)
while True:
  if not d & set(str(n)):
    exit(print(n))
  n += 1

Solution (Python):
n,k = map(int,input().split())
D = list(map(str,input().split()))
for i in range(n,10**7):
    for j in str(i):
        if j in D:
            break
    else:
        print(i)
        break

Solution (Python):
n,k = map(int,input().split())
D = set(map(str,input().split()))
for i in range(n,10**7):
    for j in str(i):
        if j in D:
            break
    else:
        print(i)
        break

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

tmp = set(['0','1','2','3','4','5','6','7','8','9'])

while len(D&set(str(N))) != 0:
    N+=1
print(N)

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

curr_num = N
while True:
    n_str = str(curr_num)
    for d in dl:
        if d in n_str:
            curr_num += 1
            break
    else:
        print(curr_num)
        break

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

candidate_num=set(['0','1','2','3','4','5','6','7','8','9'])-d

while True:
    if set(list(str(n)))<=candidate_num:
        print(n)
        exit()
    else:
        n+=1

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

tmp = set(['0','1','2','3','4','5','6','7','8','9'])

while len(D&set(str(N))) != 0:
    N+=1
print(N)

Solution (Python):
def ret_num(num, val):
  for i in num:
    if i > val:
      return i

def check(num, val):
  while val > 0:
    if val % 10 not in num:
      return False
    val//=10
  return True
    
all_num=[0,1,2,3,4,5,6,7,8,9]
(val, dis)=[int(x) for x in input().split()]
dis_num=[int(x) for x in input().split()]
num=[]
for i in all_num:
  if i not in dis_num:
    num.append(i)
while True:
  if check(num, val):
    print(val)
    break
  else:
    val+=1

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
n=str(n)
cand=[]
flag=True
for i in range(10):
    if not i in lis:
        cand.append(i)
mx=""
for i in range(len(n)):
    mx+=str(cand[-1])
if int(n)>int(mx):
    flag=False
stri=""
if flag==False:
    if 0 in cand:
        v=str(cand[1])
        stri+=v
        for i in range(len(n)):
            stri+="0"
        
    else:
        v=str(cand[0])
        for i in range(len(n)+1):
            stri+=v
    print(stri)
else:
    for i in range(int(n),10000):
        y=str(i)
        cou=0
        for j in range(len(y)):
            if int(y[j]) in cand:
                cou+=1
        
        if cou==len(y):
            print(y)
            sys.exit()

Solution (Python):
n, k = map(int, input().split())
dd = list(map(int, input().split()))
frag = 1
for i in range(n, 10*n+1):
  frag = 1
  for d in dd:
    if(str(d) in str(i)):
      frag = 0
  if(frag):
    print(i)
    break

Solution (Python):
N,K = map(int,input().split())
D = list(input().split())
for i in range(N,10*N+1):
    ans = True
    for j in D:
        if str(i).count(j) > 0:
            ans = False
            break
    if ans == True:
        print(i)
        break

Solution (Python):
class A:

    def solve(self):
        [a, b, c] = sorted([int(x) for x in input().split(" ")])
        if a == 5 and b == 5 and c == 7:
            print("YES")
        else:
            print("NO")

class B:

    def solve(self):
        [n, l] = [int(x) for x in input().split(" ")]

        strings = []
        for r in range(n):
            strings.append(input())

        sorted_strings = sorted(strings)

        print("".join(sorted_strings))

class C:

    def fix(self, final_amount, likes):
        i = 0
        import bisect as b
        changed = False
        for i,x in enumerate(reversed(final_amount)):
            real_index = len(final_amount) - i - 1
            ind = b.bisect_right(likes, int(x))
            if ind != len(likes):
                final_amount[real_index] = str(likes[ind])
                changed = True
                break

        if not changed:
            ind = b.bisect_right(likes, 0)
            final_amount = [str(likes[ind])] + final_amount
            i = 1
        else:
            i = len(final_amount) - i - 1

        while i < len(final_amount):
            final_amount[i] = str(likes[0])
            i += 1

        return final_amount

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        dislikes = [int(x) for x in input().split(" ")]

        likes = []
        for r in range(10):
            if r not in dislikes:
                likes.append(r)

        import bisect as b

        final_amount = []
        sn = str(n)
        for ind in range(len(sn)):
            c = sn[ind]
            i = b.bisect_left(likes, int(c))
            if i == len(likes):
                prev_len = len(final_amount)
                final_amount = self.fix(final_amount, likes)
                final_amount += [str(likes[0]) for r in range(len(sn) - prev_len)]
                break

            if str(c) != str(likes[i]):
                final_amount.append(str(likes[i]))
                final_amount += [str(likes[0]) for r in range(len(sn) - len(final_amount))]
                break

            final_amount.append(str(likes[i]))

        print("".join(final_amount))

C().solve()

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

num = []

for i in range(10):
  if i not in D:
    num.append(str(i))
ans = 10**18
for i in product(num,repeat=len(str(N))):
  money = int(''.join(list(i)))
  if N <= money :
    ans = min(ans,money)
if ans == 10**18:
  for i in product(num,repeat=len(str(N))+1):
    money = int(''.join(list(i)))
    if N <= money :
      ans = min(ans,money)
print(ans)

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
available = [i for i in range(10) if i not in D]

values = [0]
idx = 0
while True:
  base = values[idx] * 10
  for a in available:
    n = base + a
    if n >= N:
      print(n)
      quit()
    values.append(n)
  idx += 1

Solution (Python):
from itertools import product
n, k = input().split()
a = list(input().split())
l = set([str(i) for i in range(10)]).difference(a)
ni = int(n)
ans = int('99'+n)
for j in range(len(n), len(n)+2):
    for i in product(l, repeat=j):
        t = int(''.join(i))
        if t >= ni:
            ans = min(t, ans)
print(ans)

Solution (Python):
inf = 10**18
mod = 10**9+7


def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


n,k = map(int, input().split())
d = list(input().split())
ans = n
for i in range(n, n*10+1):
    tmp = str(i)
    ok = True
    for c in tmp:
        if c in d:
            ok = False
            break
    if ok:
        ans = i
        break
print(ans)

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

while len(set(str(N))&D)>0:
  N+=1

print(N)

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

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

Solution (Python):
from collections import deque
n,k = map(int,input().split())
d = set(list(map(int,input().split())))
a = list({0,1,2,3,4,5,6,7,8,9} - d)
a.sort()
que = deque()
que.append(0)

while que:
    ans = que.popleft()
    if ans >= n:
        print(ans)
        exit()
    for i in a:
        que.append(ans*10 + i)

Solution (Python):
[n,k] = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
dic = {}
iter = 0
for i in range(10):
    try:
        if i != d[iter]:
            dic[str(i)] = 1
        else:
            dic[str(i)] = 0
            iter += 1
    except:
        dic[str(i)] = 1
        pass

for i in range(n,10 ** 5):
    tmp = 1
    cand = str(i)
    for j in range(len(cand)):
        tmp *= dic[cand[j]]
    if tmp == 1:
        print(cand)
        break

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)



import itertools


from bisect import bisect_left,bisect_right

n,k=n1()
D=n1()

while True:
    t=str(n)
    for i in D:
        if t.count(str(i))>0:
            n+=1
            break
    else:
        break
print(n)

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)



import itertools


from bisect import bisect_left,bisect_right

n,k=n1()
D=n1()

t=tuple(int(i) for i in str(n))

D2=[i for i in range(10) if not i in D]

ite=list(itertools.product(D2,repeat=(len(str(n)))))

index=bisect_left(ite,t)
if index==len(ite):
    if D2[0]==0:
        ans="".join([str(D2[1])]+["0"]*len(str(n)))
    else:
        ans="".join([str(D2[0])]*(len(str(n))+1))
else:
    ans="".join([str(i) for i in ite[bisect_left(ite,t)]])
print(ans)

Solution (Python):
from itertools import*

p, _ = map(int, input().split())
nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - {int(i) for i in input().split()}
for i in count(p):
    if {int(d) for d in str(i)} - nums == set():
        print(i)
        break

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

def contain(n):
  ns=list(str(n))
  for c in ns:
    if int(c) in dset:
      return True
  return False

for i in range(N,100000):
  if not contain(i):
    print(i)
    break
else:
  print(-1)

Solution (Python):
n,k = map(int,input().split())
num_list = list(map(str,input().split()))
for i in range(n, 100005):
    j = str(i)
    flag = True
    for k in range(len(j)):
        if j[k] in num_list:
            flag = False
    if flag:
        print(i)
        exit()

Solution (Python):
n,k = list(map(int, input().split()))
ln = list(map(int, input().split()))
pay = n

while True:
    counter = 0
    for i in str(pay):
        if int(i) in ln:
            counter +=1
    if counter == 0:
        print(pay)
        break
    else:
        pay += 1

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

canidates = [i for i in range(10) if i not in d]

ans = 10**9
def bfs(s):
    global ans
    if len(s) > len(str(n))+1:
        return
    if len(s) > 0:
        res = int(s)
        if res >= n and res < ans:
            ans = res
    for i in canidates:
        bfs(s+str(i))
bfs('')
print(ans)

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

for i in range(n,n*10+1):
  s=str(i)
  for p in d:
    if p in s:
      break
  else:
    print(i)
    break

Solution (Python):
fn=str
n,k=map(int, input().split())
ds=list(map(fn, input().split()))
while any(i in fn(n) for i in ds):
  n+=1
print(fn(n))

Solution (Python):
n,k=map(int, input().split())
ds=list(map(str, input().split()))
while any(i in str(n) for i in ds):
  n+=1
print(str(n))

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
cond=True
while cond:
    cond=False
    for d in D:
        if str(d) in str(N):
            cond=True
            break
    N+=1
print(N-1)

Solution (Python):
N, K = map(int, input().split())
D = input().split()
i = 0
while i < 1:
  i = 1
  for n in str(N):
    if n in D:
      i = 0
  N += 1
print(N - 1)

Solution (Python):
n, k = input().split()
strN = list()
for num in n:
    if num not in strN: strN.append(int(num))
sorted(strN)
N = int(n)
K = int(k)
nonFavDigits = input().split()
NonFavDigits = list()
for nFD in nonFavDigits:
    NonFavDigits.append(int(nFD))
Digits = list(range(0,10))
for dig in range(0,10):
    if dig in NonFavDigits: Digits.remove(dig)
flag = 0
if(all(x in Digits for x in strN)): flag = 1
if(flag):   print(N)
else:
    finalNum = N+1
    strFN = list()
    for num in str(finalNum):
        if num not in strFN: strFN.append(int(num))
    while not all(x in Digits for x in strFN):
        finalNum+=1
        strFN = list()
        for num in str(finalNum):
            if num not in strFN: strFN.append(int(num))
    print(finalNum)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,K  = IL()
D = IL()

for i in range(N,100000):
  flag = 1
  for j in str(i):
    if int(j) in D:
      flag = 0
  if flag:
    print(i)
    exit()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]







n,k=mii()
p=limii()
q=[0,1,2,3,4,5,6,7,8,9]
arr=[]
for i in q:
    if i not in p:
        arr.append(i)
ans=10**100
for i in range(len(list(str(n))),6):
    for mat in list(product(arr, repeat=i)):
        if int("".join([str(l) for l in mat]))>=n:
            ans=min(ans,int("".join([str(l) for l in mat])))
            
print(ans)

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

for i in range(N, 10**18):
    str_i = str(i)
    flag = True
    for d in D:
        if d in str_i:
            flag = False
            break
    if flag:
        print(i)
        break

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


for i in range(N,100000):
    flag = True
    for n in str(i):
        if n in D:
            flag = False
            break
    if flag:
        print(i)
        break

Solution (Python):

import sys

"""
嫌いな数字がk個あり，それがd1~dk
N円のものを買うときの最低値
入力:
n k
d1-dk
"""


def contain(s, l):
    for i in range(len(s)):
        for j in l:
            if s[i] == j:
                return False
    else:
        return True


def main():
    n, k = map(str, input().split())
    kirai_num_list = input().split()

    if contain(n, kirai_num_list):
        print(n)
    else:
        while True:
            n = int(n) + 1
            if contain(str(n), kirai_num_list):
                print(str(n))
                sys.exit()


if __name__ == "__main__":
    main()

Solution (Python):
l = list(map(int, input().split()))

N = l[0]
K = l[1]

s = list(map(int, input().split()))

for value in range(100001):
  result = 0
  if value >= N:
    flg = 1
    for num in s:
      if str(num) in str(value):
        flg = 0
        break
    if flg == 1:
      result = value
      break
print(result)

Solution (Python):
K, N = map(int, input().split())
liked_num = [0,1,2,3,4,5,6,7,8,9]
disliked_num = list(map(int, input().split()))
for s in disliked_num:
    liked_num.remove(s)
cnt = K
flag = 1
while flag:
    not_n = 1
    for i in str(cnt):
        if not int(i) in liked_num:
            not_n = 0
            break
    if not_n:
        break
    cnt += 1
print(cnt)

Solution (Python):
n, k = map(int, input().split())
d = set(input().split())
for i in range(n, 10*n):
    for c in str(i):
        if c in d:
            break
    else:
        print(i)
        break

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

a = []
for i in range(10):
    if i not in d:
        a.append(i)

check = set(a)
for i in range(10**5):
    if i >= n and set(map(int, list(str(i)))) <= set(a):
        print(i)
        exit()

Solution (Python):
from collections import deque
n , k = map(int,input().split())
d = set(list(map(int,input().split())))
kouho =list({0,1,2,3,4,5,6,7,8,9} - d)
kouho.sort()

p = deque()
p.append(0)

while p:
    now = p.popleft()
    if now >= n:
        print(now)
        exit()
    for i in kouho:
        p.append(now*10+i)

Solution (Python):
n, k = map(int,input().split())
d = set(input().split())
 
while True:
    for c in str(n):
        if c in d:
            break
    else:
        print(n)
        exit()
    n += 1

Solution (Python):
n, k = map(int, input().split())
ds = [i for i in input().split()]

while True:
    if len([n_ for n_ in str(n) if n_ in ds]) == 0:
        break
    else:
        n += 1
print(n)

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
number=[i for i in range(10) if i not in D]

for i in range(N,N*10):
    c=0
    for j in str(i):
        if int(j) not in number:
            c=1
            break
    if c==0:
        print(i)
        break

Solution (Python):
if __name__ == '__main__':
  N, K = map(int, input().split())
  D = list(input())
  
  x = N
  while True:
    if all(y not in D for y in list(str(x))):
      if x >= N:
        print(x)
        break
    x += 1

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

y = N
while True:
    if all(a not in D for a in list(str(y))):
        if y >= N:
            print(y)
            break
    y += 1

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

y = 1
while True:
    if all(a not in D for a in list(str(y))):
        if y >= N:
            print(y)
            break
    y += 1

Solution (Python):
N,K = map(int,(input().split()))
D = list(map(int,(input().split())))
for i in range(N,100000):
    for j in D:
        if str(j) in str(i):
            break
    else:
        print(i)
        break

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

for x in range(N,10**6):
  x = str(x)
  judge = 1
  for xi in x:
    if(xi in D):
      judge = 0 
  if(judge == 1):
    ans = x
    break
    
print(ans)

Solution (Python):
import numpy as np
 
n, k = map(int, input().split())
 
hate = list(map(int, input().split()))
 
while True:
    for c in str(n):
        if int(c) in hate:
            break
    else:
        print(n)
        exit()
    n += 1

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

Solution (Python):
n, k = map(int, input().split())
d = [i for i in range(10)]
[d.remove(int(x)) for x in input().split()]
n_len = len(str(n))

def rec_define_digit(s):
    v = int(s)
    
    if v >= n:
        return v
    ans = 999999
    if len(s) >= n_len + 2:
        return ans
    for i in d:
        ans = min(rec_define_digit(s + str(i)), ans)
    return ans

print(rec_define_digit("0"))

Solution (Python):
import itertools

n, k = map(int, input().split())
d = [i for i in range(10)]
[d.remove(int(x)) for x in input().split()]
n_len = len(str(n))

ans = -1
for x in itertools.product(d, repeat=n_len):
    v = int("".join([str(i) for i in list(x)]))
    
    if v >= n:
        if ans < 0 or ans > v:
            ans = v

if ans < 0:
    for x in itertools.product(d, repeat=n_len+1):
        v = int("".join([str(i) for i in list(x)]))
        
        if v >= n:
            if ans < 0 or ans > v:
                ans = v

print(ans)

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

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

Solution (Python):
import numpy as np

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

hate = list(map(int, input().split()))

while True:
    for c in str(n):
        if int(c) in hate:
            break
    else:
        print(n)
        exit()
    n += 1

Solution (Python):
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(n,10*n+1):
    m =list(map(int,str(i)))
    no = 0
    for j in range(len(m)):
        if m[j] in a:
            no = 1
            break
    if no == 0:
        print(i)
        break

Solution (Python):
import sys
sys.setrecursionlimit(500000)

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

ans = []
def dfs(p:str):
    if int(p)>=n:
        ans.append(int(p))
        return

    if len(p)>len(str(n))+1:
        return

    for i in range(10):
        if not i in D:
            dfs(p+str(i))

for i in range(10):
    if not i in D:
        dfs(str(i))

print (min(ans))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    D=set(input().split())
    for i in range(N,10**7):
        if not set(str(i))&D:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Solution (Python):
n,k = map(int,input().split()) 
a = list(map(int,input().split())) 
b = {0,1,2,3,4,5,6,7,8,9}-set(a) 
while set([int(i) for i in list(str(n))])-b !=set() : 
    n += 1
print(n)

Solution (Python):
import copy
n,k = map(int,input().split())
d = input().split()
nd = list(map(str,range(10)))
for i in d:
  nd.remove(i)
l = len(str(n))
if "0" in nd:
  a1 = 1
else:
  a1 = 0
alist = nd[a1:]
for _ in range(l-1):
  tlist = []
  for i in alist:
    for j in nd:
      tlist.append(i+j)
  alist = copy.copy(tlist)
alist.append(nd[a1]+nd[0]*l)
for i in alist:
  if n <= int(i):
    print(i)
    exit()

Solution (Python):
n,k = map(int,input().split())
d = input().replace(" ","")
for i in range(n,10**9):
  check = True
  for j in str(i):
    if j in d:
      check = False
      break
  if check:
    print(i)
    break

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
lis = []
for i in range(10):
    if not i in d:
        lis.append(i)
inf = 1001001001
ans = inf
def dfs(s, n):
    if len(s) >= len(str(n)) + 2:
        return
    if len(s) > 0 and int(s) >= n:
        global ans
        ans = min(ans, int(s))
    else:
        for i in lis:
            dfs(s + str(i), n)
dfs("", n)
print(ans)

Solution (Python):
N, K = map(int,input().split())
D = set(map(str,input().split()))
res = N
while 1:
    flg = 0
    for char in str(res):
        if char in D:
            flg = 1
    if flg == 1:
        res += 1
        continue
    break
print(res)

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

while True:
    s = str(n)
    f = 1
    for i in range(len(s)):
        if s[i] in d:
            f = 0
        else:
            pass

    if f:
        print(s)
        break
    else:
        n += 1

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

while (1):
   c = [x for x in str(n)]

   ok = 1
   for x in c:
      if x in d:
         ok = 0
         break

   if ok == 1:
      break

   n += 1

print(n)

Solution (Python):

N,K=map(int,input().split())
D=input().split()
n=N
while 1:
  flg=True
  for i in range(K):
    if D[i] in list(str(n)):
      flg=False
     
  if flg:
    break
  else:
    n+=1
print(n)

Solution (Python):
n, k = map(int, input().split())
dislike = list(map(int, input().split()))
for i in range(n,10**18):
    a = str(i)
    
    flag = True
    for j in range(len(a)):
        
        for k in dislike:
            
            if int(a[j]) == k:
                flag = False
                break
        if flag == False:
            break
    if flag == True:
        print(i)
        break