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






import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *


BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def main():
    n,k=map(int,input().split())
    d=list(map(int,input().split()))
    mx=100000
    ans=100000
    while mx>=0:
        temp=str(mx)
        f=True
        for i in range(len(temp)):
            if int(temp[i]) in d:
                f=False
                break
        if f and mx>=n:
            ans=min(ans,mx)
        mx=mx-1
    print (ans)

if __name__ == "__main__":
    main()

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

for i in range(n, n*10):
    a = set(str(i))
    for l, m in enumerate(a):
        if m in d:
            break
        elif l == len(a)-1:
            print(i)
            sys.exit()

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

for p in range(n,10**5):
    tmp=p
    d1=tmp%10

    while tmp>0 and d1 not in d:
        tmp//=10
        d1=tmp%10
    
    if tmp==0:
        print(p)
        exit(0)

Solution (Python):
n, k = map(int, input().split())
D = list(map(str, input().split()))
money = n
ok = True
while True:
    for d in D:
        if d in str(money):
            ok = False
            break
    if ok:
        print(money)
        break
    money += 1
    ok = True

Solution (Python):
n, k = map(int, input().split())
D = list(map(str, input().split()))
money = n
ok = True
while True:
    for d in D:
        if d in str(money):
            ok = False
            break
    if ok:
        print(money)
        break
    money += 1
    ok = True

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

ok = []
for i in range(10):
  if i not in A:
    ok.append(i)

while True:
  nstr = str(N)
  nstr = list(nstr)
  
  Flag = True
  for x in nstr:
    x = int(x)
    if x in A:
      Flag = False
      break
  
  if Flag:
    print(N)
    exit()
  else:
    N += 1

Solution (Python):
n, k = map(int, input().split())
dlst = list(map(int, input().split()))
ans = n
while 1:
    for num in dlst:
        if str(num) in str(ans):
            break
    else:
        print(ans)
        exit()
    ans += 1

Solution (Python):
n, k = map(int, input().split())
d = set(map(int, input().split()))
ok = set(range(10))
ans = 0
for i in range(n, 100000):
    ans = i
    flag = False
    while i != 0:
        if i % 10 in d:
            flag = True
            break
        i = i // 10
    if not flag:
        print(ans)
        break

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

for i in range(N,N+10**6+5):
  if not set(str(i)).intersection(D):
    print(i)
    exit()

Solution (Python):
N,K,*D = map(int, open(0).read().split())
Ds = set(D)
item = set([0,1,2,3,4,5,6,7,8,9]) - Ds
strs = set(str(x) for x in item)
for i in range(N,10000):
    s = set(str(i))
    if s.issubset(strs):
        print(i)
        break
else:
    il = list(item)
    il.sort()
    if il[0] == 0:
        ans = [str(il[1])] + ([str(il[0])]*len(str(N)))
        print(''.join(ans))
    else:
        ans = ([str(il[0])]*(len(str(N))+1))
        print(''.join(ans))

Solution (Python):
N, L = map(int, input().split())
S = {int(x) for x in input().split()}
flag = False
while 1:
    if N%10 in S:
        N += 1
        continue
    if int((N%100-N%10)/10) in S and N >= 10:
        N += 1
        continue
    if int((N%1000-N%100)/100) in S and N >= 100:
        N += 1
        continue
    if int((N%10000-N%1000)/1000) in S and N >= 1000:
        N += 1
        continue
    if int((N%100000-N%10000)/10000) in S and N >= 10000:
        N += 1
        continue
    break
print(N)

Solution (Python):
N, L = map(int, input().split())
S = {int(x) for x in input().split()}
flag = False
while flag == False:
    if N%10 in S:
        N += 1
        continue
    if int((N%100-N%10)/10) in S and N >= 10:
        N += 1
        continue
    if int((N%1000-N%100)/100) in S and N >= 100:
        N += 1
        continue
    if int((N%10000-N%1000)/1000) in S and N >= 1000:
        N += 1
        continue
    if int((N%100000-N%10000)/10000) in S and N >= 10000:
        N += 1
        continue
    flag = True
print(N)

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

flag=0

for i in range(100000):
    S=N+i
    flag=0
    for j in range(len(str(S))):
        if int(str(S)[j]) not in d:
            flag+=1
            if flag==len(str(S)):
                print(S)
                break
    else:
        continue
    break

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

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")



def main():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ng = [False]*10
    for d in D:
        ng[d] = True

    for n in range(N, 10*N+1):
        d = str(n)
        flg = True
        for i in range(len(d)):
            if ng[int(d[i])]:
                flg = False
        if flg:
            print(n)
            return


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
d = LIST()
num = []
for i in range(10):
    if i not in d:
        num.append(i)
ans = inf
for i in range(5):
    for x in product(num,repeat=i+1):
        tmp = 0
        for j in range(i+1):
            tmp += x[j]*10**j
        if tmp >= n:
            ans = min(ans, tmp)
print(ans)

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

Solution (Python):
N,K=map(int, input().split(" "))
s=input().split(" ")
i=N

while i < 10*N:
    j = list(str(i))
    if not set(j).isdisjoint(set(s)): 
        i += 1
    else:
        print(i)
        break

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

while 1:
    for num in dlst:
        if num in str(n):
            break
    else:
        print(n)
        break
    n += 1

Solution (Python):
def main():
  n, k = input().split()
  a=set(input().split())
  while True:
      n1=set(n)
      if n1 & a == set():
          print(n)
          break
      else:
          n=int(n)
          n+=1
          n=str(n)
  
  
if __name__=="__main__":
  main()

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

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

m = len(str(n))
for i in range(m, m+2):
  for j in product(nums, repeat=i):
    ans = ""
    for k in j: ans += str(k)
    if int(ans) >= n:
      print(ans)
      exit()

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

while True:
  sN = str(N)
  flag = False
  for ins in D:
    if str(ins) in sN:
      flag = True
      break
  if flag:
  	
  	N += 1
  else:
  	break

print(N)

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
for i in range(n, 10 * n + 1):
    flag = False
    for j in str(i):
        if int(j) in d:
            flag = True
            break
    if flag:
        continue
    exit(print(i))

Solution (Python):
N, K = [1000, 8]
DRR = [1, 3, 4, 5, 6, 7, 8, 9]



N, K = [9999, 1]
DRR = [0]


N, K = list(map(int,input().split()))
DRR = list(map(int,input().split()))

def calculate(n, k, drr):
    dislikes = set()

    for i in range(k):
        dislikes.add(drr[i])

    while not condition(n, dislikes):
        n += 1

    print(n)
def condition(n,dislikes):
    arr = list(map(int, str(n)))

    for i in range(len(arr)):
        if  dislikes.__contains__(arr[i]):
            return False
    return True


calculate(N, K, DRR)

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,100000):
    num=list(str(i))
    num1=0
    for j in range(len(num)):
        if num[j] in d:
            num1=1
            break
    if num1==0:
        print(i)
        break

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

for i in range(n,100000):
  i2=str(i)
  for m in d:
    if m in i2:
      break
  else:
    print(i)
    exit()

Solution (Python):
def check(n,s):
    v=str(n)
    for i in v:
        if i in s:
            return False
    return True
def solve():
    n,k=map(int,input().split())
    s=input().split()
    s=set(s)
 
    while True:
        if check(n,s):
            print(n)
            break
        else:
            n+=1
for _ in range(1):
    solve()

Solution (Python):
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

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

def check(n,s):
    v=str(n)
    for i in v:
        if i in s:
            return False
    return True
    

    
def solve():
    n,k=mp()
    s=input().split()
    s=set(s)

    while True:
        if check(n,s):
            print(n)
            break
        else:
            n+=1
        

        
        

for _ in range(1):
    solve()

Solution (Python):
i = 0
k_n = []
k_n_all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

p_price, k_number = map(int, input().split())
k_n = map(int, input().split())
result_number = list(set(k_n_all) - set(k_n))
result_price = p_price

while True:
    x = 0
    y = 0
    z = list(map(int, str(result_price)))
    while x < len(z):
        if z[x] in result_number:
            y += 0
        else:
            y += 1
        x += 1

    if y == 0:
        print(result_price)
        break
    else:
        result_price += 1

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    D = set(LSS())

    for i in range(N, N * 10 + 1):
        if [(j in D) for j in str(i)].count(True) == 0:
            print(i)
            break

if __name__ == '__main__':
    resolve()

Solution (Python):
n,k=map(int,input().split())
a=list(input().split())
ans=0
for i in range(n,100001):
  cnt=list(str(i))
  for j in range(len(cnt)):
    if cnt[j] in a:
      ans=1
      break
  if ans==0:
    print(i)
    exit()
  else:
    ans=0
    continue

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

while True:
    l=list(str(n))
    for i in l:
        if i in D:
            break
    else:
        break
    n+=1
    
print(n)

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

    while True:
        flg = 0
        for i in str(n):
            i = int(i)
            if i in D:
                flg = 1
                break
        if flg == 0:
            break
        n+=1

    print(n)

main()

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    cuse = list(set(d) ^ set(range(10)))
    for i in range(n, 200000):
        nyoso = list(set(map(int, list(str(i)))))
        bit = 0
        for j in nyoso:
            if j in cuse:
                bit += 1
            else:
                break
        if bit == len(nyoso):
            print(i)
            break
    return 0

if __name__ == "__main__":
    solve()

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

for n in range(N, N * 10 + 1):
    ok = True
    for c in str(n):
        if c in D:
            ok = False
    if ok:
        print(n)
        break

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

for n in range(N, 100000):
    s = str(n)
    ok = True
    for c in s:
        if c in D:
            ok = False
    if ok:
        print(n)
        break

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

allowed = {i for i in range(10) if i not in d}
maxn = 10**5

for k in range(1,maxn+1):
    if k >= n and all(int(c) in allowed for c in str(k)):
        print(k)
        break

Solution (Python):
n,k=map(int,input().split())
ar=list(map(int,input().split()))
def f(n):
    s=str(n)
    for el in ar:
        if(str(el) in s):
            return 0
    return 1
while(not f(n)):
    n+=1
print(n)

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

allowed = {i for i in range(10) if i not in d}

MAXN = 10 ** 5


def answer():
    for k in range(1, MAXN + 1):
        if k >= n and all(int(c) in allowed for c in str(k)):
            return k


answer = answer()
print(answer)

Solution (Python):
def main():
  n,k=input().split()
  a=set(input().split())
  while True:
      n1=set(n)
      if n1 & a == set():
          print(n)
          break
      else:
          n=int(n)
          n+=1
          n=str(n)
  
  
if __name__=="__main__":
  main()

Solution (Python):
N, K = map(int, input().split())
D = set(list(input().split()))
while N < 10 ** 6:
    if len(set(list(str(N))) & D) == 0:
        print(N)
        exit()
    N += 1

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

i=n
while True:
    check=0
    for number in d:
        if not number in str(i):
            continue
        else:
            check=1
            break
    if check==0:
        print(i)
        break
    else:
        i+=1

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

n_str = str(n)
l = len(n_str)
a = [i for i in range(10) if i not in d]


ans = ""
for i in range(l):
    for j in a:
        if j == int(n_str[i]):
            ans += str(j)
            break
        elif j > int(n_str[i]):
            ans += str(j) + str(a[0])*(l-i-1)
            print(ans)
            exit()

if len(ans)>0:
    if int(ans) >= n:
        print(ans)
        exit()

if 0 in a:
    ans = str(a[1]) + str(a[0])*l
else:
    ans = str(a[0])*(l+1)

print(ans)

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

D = list(map(str, input().split()))

while True:
    n = str(N)
    nn = str(N)

    for o in nn:
        if o in D:
            N += 1
            nn = str(N)
            break

    if n == nn:
        break

print(N)

Solution (Python):


def main():


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

    numList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    num = set()
        
    for i in numList:
        if i not in D:
            num.add(i)
    

    for i in range(N, N * 10 + 1):
        setI = set(int(x) for x in list(str(i)))
        if len(num | setI) <= len(num):
            ans = i
            break
                
    print(ans)


if __name__ == "__main__":
    main()