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




def main():
    N, K = input().split(' ')
    D = set(map(int, input().split(' ')))
    can_use_num = set(map(str, set(range(10)) - D))

    n = int(N)
    while True:
        if set(str(n)) <= can_use_num:
            break
        n += 1
    print(n)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import sys

def getinputdata():

    
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()


n = arr_data[0][0]


k = int(arr_data[0][1])


arr=arr_data[1]



chkflg=True

while chkflg:
    
    for v in n:
        
        if v in arr:
            
            n = str(int(n)+1) 
            break
            
    else:
        
        chkflg=False
        
print(n)

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
while True:
    m=n
    f=False
    while m>0:
        if m%10 in d:
            f=True
            break
        m=int(m/10)
    if f:
        n+=1
    else:
        print(n)
        break

Solution (Python):
import sys
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,100000):
  s=str(i)
  for j in d:
    if(j in s):
      break
  else:
    print(i)
    sys.exit()

Solution (Python):
import bisect
n,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
N = list(n)

D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

mv = str(D_bar[0])
ld = 10 - int(K)
l = len(N)
index = -1
for i in range(l):
	if int(N[i]) in D:
		index = i
		break

if index == (-1):
	print(n)
	exit(0)

for i in range(index,-1,-1):
	p = bisect.bisect_left(D_bar,int(N[i]))
	if p == ld:
		N[i] = mv
		if i == 0:
			m = str(D_bar[0]) if D_bar[0] != 0 else str(D_bar[1])
			N[0] = mv
			N.insert(0,m)
		else:
			N[i-1] = str(int(N[i-1]) + 1)
	else:
		N[i] = str(D_bar[p])
		break

for i in range(index+1,len(N)):
	N[i] = mv
print(''.join(N))

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


while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        if i==len(str(n))-1:
            print(n)
            exit()
    n+=1

Solution (Python):
n,m = map(int,input().split())
lis = list(map(str,input().split()))
while 1:
    for i in range(len(str(n))):
        if str(n)[i] in lis:
            break
        if i == len(str(n))-1:
            print(n)
            exit()
    n += 1

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

Solution (Python):
n,k=map(int,input().split())
d=set(input().split())
a=[]
for i in range(n,10*n):
    if not set(str(i))&set(d):
        print(i)
        exit()

Solution (Python):
n, k = map(int,raw_input().split())
s = set(raw_input().split())
for i in range(n,100000):
	if len(s - set(list(str(i)))) == k:
		print i
		break

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

while True:
    flag=False
    for i in range(len(str(n))):
        if int(str(n)[i]) in d:
            flag=True
            break
    if flag==True:
        n+=1
    else:
        print(n)
        break

Solution (Python):

T = 1

def check(n, D):
    a = map(lambda x : ord(x) - ord('0'), str(n))
    for i in a:
        if i in D:
            return False
    return True


def get(n, D):
    while True:
        if check(n, D):
            return n
        n += 1
    return n

for i in range(T):
    n, k = map(int, raw_input().split())
    D = map(int, raw_input().split())
    D = set(D)
    print get(n, D)

Solution (Python):
n,k=raw_input().split();u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()));z=u[0];n=list(n)
for i,d in enumerate(n):
 if d in u:continue
 n[i:]=[next(e for e in u if e>d)]+[z]*(len(n)-i-1)
 for j in range(i-1,-1,-1):
  if n[j+1]<':':break
  n[j:j+2]=[next(e for e in u if e>n[j]),z]
 else:
  if n[0]>'9':n=[u[1 if'1'>z else 0]]+[z]*len(n)
print"".join(n)

Solution (Python):
n, k = map(int,raw_input().split())
s = set(raw_input().split())
for i in range(n,100000):
	if len(s - set(list(str(i)))) == k:
		print i
		break

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
while True:
    m=n
    f=False
    while m>0:
        if m%10 in d:
            f=True
            break
        m=int(m/10)
    if f:
        n+=1
    else:
        print(n)
        break

Solution (Python):
n, _ = map(int, raw_input().split())
d = set(map(int, raw_input().split()))
while len(set(map(int, str(n))) & d) > 0:
    n += 1
print n

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0

solve()

Solution (Python):
n,k=map(int, input().split())
arr=list(map(int,input().split()))
x=1
while x!=0:
	x=0
	n+=1
	for i in range(k):
		if str(n-1).find(str(arr[i]))!=-1:
			x+=1
print(n-1)

Solution (Python):


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

ans = N
while True:
    ans = str(ans)
    for num in D:
        if ans.find((str(num))) != -1:
            break
    else:
        break
    ans = int(ans) + 1

print(ans)

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

Solution (Python):
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    for ii in range(n, 10**9):
        l = [int(x) for x in list(str(ii))]
        ll =[q for q in l if q in d]
        if len(ll) == 0:
            print(ii)
            break
if __name__ == "__main__":
    main()

Solution (Python):
def valid(num,l):
    while(num>0):
        if (num%10) in l:
            return 0
        num = num//10
    return 1

n,k=map(int,input().split(' '))
l = [int(x) for x in input().split(' ')]
for i in range(100000):
    if valid(n+i,l) == 1:
        print(n+i)
        break

Solution (Python):

N, K = map(int, input().split())
D = list(map(int, input().split()))
for tmp in range(N, 10*N+1):
    flag = True
    factor = list(map(int, str(tmp)))
    for num in D:
        if num in factor:
            flag = False
            break
    if flag:
        print(tmp)
        break

Solution (Python):

import itertools

def main():
    N, K = input().split()
    l = list(set(list('0123456789')) - set(input().split()))
    t = int(N)
    m = 100000
    for i in itertools.product(l, repeat=len(N)):
        if int(''.join(i)) >= t:
            m = min(m, int(''.join(i)))
    for i in itertools.product(l, repeat=len(N)+1):
        if int(''.join(i)) >= t:
            m = min(m, int(''.join(i)))
    print(m)
if __name__ == '__main__':
    main()

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

n = N
while True:
    if len(set(str(n)) & D) == 0:
        print(n)
        break
    n += 1

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))


N, K = rli()
D = set(map(int, input().split()))
All = {1,2,3,4,5,6,7,8,9,0}
All.difference_update(D)

ans = N
for i in range(N*10):
    ls = set(map(int, str(ans)))
    ls.difference_update(All)
    if(ls == set()):
        print(ans)
        break
    ans += 1

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(100000):
    for x in str(N):
        if x in D:
            break
    else:
        print N
        break
    N += 1

Solution (Python):



def main(n, D):
    D = set(D)
    while set(str(n)) & D:
        n += 1
    return n


if __name__ == '__main__':
    n, _ = [int(e) for e in input().split()]
    D = [e for e in input().split()]
    print(main(n, D))

Solution (Python):
import itertools
n,_=map(int,input().split())
b=map(int,input().split())
l=len(str(n))
c=set(b)^set([0,1,2,3,4,5,6,7,8,9])
for i in range(l,l+2):
    for x in itertools.product(c,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=n:print(d);exit()

Solution (Python):
import itertools
a=set([0,1,2,3,4,5,6,7,8,9])
n,_=map(int,input().split())
b=map(int,input().split())
l=len(str(n))
c=set(b)^a
for i in range(l,l+2):
    for x in itertools.product(c,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=n:print(d);exit()

Solution (Python):


inpt = input().split(" ")

maxNum = inpt[0]

dislike = input().split(" ")
dislike = [int(a) for a in dislike]

likeArray = []

for i in range(0,10):
    if not i in dislike:
        likeArray.append(i)

ans = ""
flag = False
for c in maxNum:
    if flag :
        ans += str(min(likeArray))
    else:
        if int(c) in likeArray:
            ans += c
        elif len([a for a in likeArray if a > int(c)])>0:
            ans += str(min([a for a in likeArray if a > int(c)]))
            flag = True
        else:
            ans = str(min([a for a in likeArray if a > 0]))
            for i in range(0, len(maxNum)):
                ans += str(min(likeArray))
            break    
print(ans)

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

f=1
a=n
while f==1:    
    for i in range(k):
        if str(d[i]) in list(str(a)):
            f=1
            a+=1
            break
    else:
        f=0
print a

Solution (Python):
mark=[0 for i in range(10)]
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())


def check(num):
	temp=num

	while(temp>0):
		d=temp%10
		if d in l:
			return 0
		temp=temp//10
	return 1




while True:

	if check(n)==1:
		print n
		break
	n+=1

Solution (Python):

N,K=map(int,raw_input().split( ))
numlist=map(int,raw_input().split( ))
def checknum(num):
    t = num
    while(t):
        check=t%10
        k=0
        while(k<K):
            if check == numlist[k]:
                return 0
            k+=1
        t=t/10
    return 1


while(1):
    if(checknum(N)):
        print N
        break
    N+=1

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ipair():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def spair():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    else:
        return -1




n,k = ipair()
d = map(int,raw_input().split(" "))

while 1:
    flag = 1
    for a in list(str(n)):
        if index(d,int(a))!=-1:
            flag = 0
    if flag:
        print n
        break
    n += 1

Solution (Python):


inputs = map(int, raw_input().split())
n = inputs[0]
k = inputs[1]
d = map(int, raw_input().split())
p = []

p.append(n//10000)
p.append(n//1000 - p[0]*10)
p.append(n//100 - p[0]*100 - p[1]*10)
p.append(n//10 - p[0]*1000 - p[1]*100 - p[2]*10)
p.append(n%10)

topindex = 0

for i in range(5):
    if p[i] != 0:
        topindex = i
        break

    
while True:
    dex = 0
    for i in range(topindex,5):
        if p[i] in d:
            dex = 1
    if dex == 1:
        n += 1
        p = []
        p.append(n//10000)
        p.append(n//1000 - p[0]*10)
        p.append(n//100 - p[0]*100 - p[1]*10)
        p.append(n//10 - p[0]*1000 - p[1]*100 - p[2]*10)
        p.append(n%10)

        topindex = 0

        for i in range(5):
            if p[i] != 0:
                topindex = i
                break
    else:
        break

print(n)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
while any(s in D for s in str(N)):
    N += 1
print(N)

Solution (Python):
from functools import reduce
import operator as op

def mapAccumL(f, acc, xs):
    ys = []
    for x in xs:
        (acc, y) = f(acc, x)
        ys.append(y)
    return (acc, ys)

def unfoldl(f, init, finish):
    acc = init
    while not finish(acc):
        acc, y = f(acc)
        yield y

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = set(map(int, ds_str))

for m in range(n, 100000):
    mlist = list(unfoldl(lambda acc: (acc//10, acc%10), m, lambda acc: acc == 0))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break

Solution (Python):
from functools import reduce
import operator as op

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = set(map(int, ds_str))

for m in range(n, 100000):
    mlist = map(int, list(str(m)))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break

Solution (Python):
from functools import reduce
import operator as op

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = list(map(int, ds_str))

for m in range(n, 100000):
    mlist = map(int, list(str(m)))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break

Solution (Python):
N, K = raw_input().split()
D = set(map(int,raw_input().split()))
L = sorted(set(range(10))-D)

pay=[]
for ind, d in enumerate(N):
    if ind == 0:
        w = len(N)
        ma, mi = max(L), min(L)
        tmp = ''.join([str(ma)]*w)
        tmp = int(tmp)
        if tmp < int(N):
            if L[0]==0:
                pay = [str(L[1])]+['0']*w
            else:
                pay = [str(L[0])] * (w+1)
            break

    if int(d) in D:
        for l in sorted(L):
            if l > int(d):
                pay+= [str(l)]+[str(L[0])]*(w-len(pay)-1)
                break
        else:
            for l in sorted(L):
                if l > int(N[ind - 1]):
                    pay = pay[:-1] + [str(l)] * (w - len(pay) + 1)
                    break
        break
    else:
        pay.append(d)

print ''.join(pay)

Solution (Python):
from collections import deque
n = map(int, raw_input().split())
n = n[0]

d = map(int, raw_input().split())
e = range(0,10)
for dd in d:
    e.remove(dd)

sn = str(n)
indexes = deque()
bg = False
for cn in sn:
    dn = int(cn)
    i = 0
    if bg:
        indexes.append(0)
        continue
    while i < len(e) and dn > e[i]:
        i+=1
    if i != len(e):
        indexes.append(i)
        if dn < e[i]:
            bg = True

    else: 
        j = -1
        while -j < len(indexes):
            if indexes[j] + 1 < len(e): 
                indexes[j] += 1
                break
            else:
                indexes[j] = 0
            j -= 1
        
        if -j >= len(indexes) : 
            indexes.clear()
            if e[0] != 0:
                indexes.append(0)
            else:
                indexes.append(1)
            for l in xrange(len(sn)):
                indexes.append(0)
            break

        indexes.append(0)
ans = ""
while len(indexes) != 0:
    i = indexes.popleft()
    ans += str(e[i])
    
print ans

Solution (Python):
def check(n):
    return all(not int(i) in D for i in str(n))

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

while True:
    if check(N):
        print N
        break
    N += 1

Solution (Python):
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])





result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            
            result = int(result + (new_num - num) * math.pow(10, index-1))
            result_str = list(str(result))
        else:
            
            result = int(result + (10 - num) * math.pow(10, index-1))
            result_str = list(str(result))
result = int(result)
while True:
    result_str = list(str(result))
    num = int(result_str[0])
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = int(result + (new_num - num) * math.pow(10, len(result_str)-1))
        else:
            result = int(result + (10 - num) * math.pow(10, len(result_str)-1))
    else:
        break

result_str = list(str(result))
base_str = list(str(amount))
for index in range(2, len(result_str)+1):
    num = int(result_str[-index])
    base_num = int(base_str[-index]) if index <= len(base_str) else None
    
    if base_num is None or num > base_num:
        result_str[-index+1:len(result_str)] = [str(non_avoids[0])] * (index - 1)

print ''.join(result_str)

Solution (Python):
N,K = map(int,raw_input().split())
D = raw_input().split()
cant = set(D)
for n in xrange(N,100000):
	u = set(list(str(n)))
	if len(cant - u) == K:
		print n
		break

Solution (Python):
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
c = n
while True:
    if not any(str(x) in str(c) for x in d):
        break
    c += 1
print(c)

Solution (Python):
import numpy as np

ret = []
use = []

def func(k, n):
    if k == 0:
        if n >= N:
            print(n)
            exit()
        return

    for i in use:
        func(k-1, n*10 + i)

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

num = np.array([i for i in range(10)])
f = np.array([True for i in range(10)])

D = list(map(int, input().split()))
for i in D:
    f[i] = False

use = num[f]

func(1, 0)
func(2, 0)
func(3, 0)
func(4, 0)
func(5, 0)

Solution (Python):

import itertools
n, k = map(int, raw_input().split())
ls = map(int, raw_input().split())
kls = []
for i in range(10):
    if i not in ls:
        kls.append(i)

ans_list = []
repeat_len = len(str(n))
while not ans_list:
    for element in itertools.product(kls, repeat=repeat_len):
        a = int("".join(map(str,element)))
        if a >= n:
            ans_list.append(a)
    repeat_len += 1
print ans_list[0]

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
while any(s in D for s in str(N)):
    N += 1
print(N)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
while any(s in D for s in str(N)):
    N += 1
print(N)

Solution (Python):


from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N, K = map(int, input().split(" "))
ds = list(map(int, input().split(" ")))
cs = []
for i in range(10):
    if i not in ds: cs.append(i)

ns = str(N)


def solve(N, digit):
    if digit == -1:
        return N
    n = int((N // (10**digit)) % 10)
    if n not in ds:
        return solve(N, digit - 1)
    else:
        new_N = N // (10**(digit + 1))
        new_N = new_N * (10**(digit + 1))
        for i in range(n + 1, 10):
            if i not in ds:
                new_N = new_N + (10**digit) * i
                return solve(new_N, digit-1)
        else:
            new_N = new_N + 10**(digit + 1)
            return solve(new_N, len(str(new_N))-1)

print(solve(N, len(str(N))-1))

Solution (Python):
import re
 
class IO_for_Contest(object):
    @staticmethod
    def my_input():
        
        return input()
 
    @staticmethod
    def read_from_input():
        n, k = IO_for_Contest.read_n_int(2)
        d = IO_for_Contest.read_n_int(k)
        return n, d
 
    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()
 
    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())
 
    @staticmethod
    def read_n_int(n):
        return list(map( \
                int, \
                re.split('\s+', IO_for_Contest.my_input().strip())))[ : n]
 
def solve():
    n, d = IO_for_Contest.read_from_input()
    print(inner_solve(n, d))

def inner_solve(n, d):
    while True:
        s_n = str(n)
        success = False
        for i in range(len(s_n)):
            if int(s_n[i]) in d:
                break
        else:
            success = True
        if success:
            return n
        n += 1

if __name__ == '__main__':
    solve()

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

for x in xrange(n, 10**6):
    for c in str(x):
        if c in D:
            break
    else:
        print x
        break

Solution (Python):
n, k = map(int, raw_input().split())
vs = set(map(int, raw_input().split()))

while True:
    ok = True
    for c in str(n):
        if int(c) in vs:
            ok = False
            break
    if ok:
        break
    n += 1
print n

Solution (Python):
n, k = map(int, raw_input().split())
is_bad = [ False for d in range(10) ]
for d in map(int, raw_input().split()):
  is_bad[d] = True

def good(x):
  while x != 0:
    d = x % 10
    if is_bad[d]:
      return False
    x //= 10
  return True

while True:
  if good(n):
    print(n)
    break
  n += 1

Solution (Python):
from itertools import product
N, K = list(map(int, input().split()))
D = set(range(10)) - set(list(map(int, input().split())))
ans = float("inf")
for i in range(2):
    for s in product(D, repeat=len(str(N))+i):
        n = int("".join(map(str, s)))
        if n >= N and ans - N > n - N:
            ans = n
print(ans)

Solution (Python):
if __file__.startswith('/tmp/'):
	import sys; sys.stdin = open('input.txt')

n, k = map(int, raw_input().split())
d = ''.join(raw_input().split())

l = len(str(n)) + 1

m = n
while True:
	s = str(m)
	ok = True
	for c in s:
		if c in d:
			ok = False
			break
	if ok:
		print s
		break
	m += 1

Solution (Python):
[N,K]=[int(x) for x in raw_input().split()]
Dlist=raw_input().split()

ans=0
while(1):
    ans+=1
    if ans>=N:
        anstr=str(ans)
        Din=0
        for D in Dlist:
            if D in anstr:
                Din=1
        if not Din:
            print ans
            break

Solution (Python):


import itertools


def solve(money, dislike_numbers):
    for dm in itertools.count():
        pay = money + dm
        if set(map(int, str(pay))).isdisjoint(dislike_numbers):
            return pay


def main():
    money, _ = map(int, input().split())
    dislike_numbers = set(map(int, input().split()))
    print(solve(money, dislike_numbers))


if __name__ == '__main__':
    main()

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

while True:
    ok = True
    for d in D:
        if str(N).find(d) >= 0:
            ok = False
            break
    if ok:
        print(N)
        break
    N += 1

Solution (Python):
n,k=map(int,raw_input().split())
D=map(int,raw_input().split())
while 1:
    cnt=0
    for i in str(n):
        if int(i) in D:break
        else:
            cnt+=1
    if cnt==len(str(n)):
        print(n)
        quit()
    n+=1

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

s = N
n = int(N)
while 1:
    if all(c not in D for c in s):
        print(n)
        break
    else:
        n += 1
        s = str(n)

Solution (Python):
N, K = map(int, input().split())
D = set(map(int, input().split()))
i = N
while True:
    j = i
    flag = True
    while j > 0:
        r = j % 10
        if r in D:
            flag = False
            break
        j //= 10
    if flag:
        print(i)
        break
    i += 1

Solution (Python):
from sys import exit
from itertools import count

def read():
  return [int(x) for x in input().split()]

(N, K) = read()
D = input().split()

for i in count(N):
  if all(not d in str(i) for d in D):
    print(i); break

Solution (Python):
n, k = [int(x) for x in raw_input().split(' ')]
d = [int(x) for x in raw_input().split(' ')]
def check(n, d):
    for v in d:
        if str(v) in str(n):
            return False
    return True
while True:
    if check(n, d):
        print n
        break
    n += 1

Solution (Python):



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

while True:
    N_str = str(N)
    if set(N_str) & D:
        N += 1
    else:
        break
print(N)