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())
hoge = input().split()

def check(num):
    for i in range(k):
        if num.find(hoge[i]) >= 0:
            return False
    return True

result = n
while(True):
    if check(str(result)):
        break
    result += 1
print(result)

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

D = [int(i) for i in input().split(' ')]

c = N

while True:
    s = [int(i) for i in list(str(c))]

    flg = False

    for i in s:
        if i in D:
            flg = False
            break
        else:
            flg = True
    
    if flg:
        print(c)
        break
    else:
        c += 1

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

while True:
    cnt = 0
    for i in range(len(W)):
        cnt += str(N).count(str(W[i]))
    if cnt == len(str(N)):
        break
    N += 1

print(N)

Solution (Python):
"""
kari1 = '2000 8'
kari2 = '0 2 4 5 8 9'
in1 = kari1.split()
in2 = kari2
"""
in1 = input().split()
in2 = input()

tukaeru = []
for num1 in range(10):
    if str(num1) not in in2:
        tukaeru.append(str(num1))
nedan = []
for num1 in range(len(in1[0])):
    nedan.append(in1[0][num1])

idx1 = 0
for item1 in nedan:
    if item1 not in tukaeru:
        break
    idx1 = idx1 + 1

if idx1 < len(nedan): 
    while idx1 >= 0:
        if tukaeru[-1] <= nedan[idx1]:
            idx1 = idx1 - 1
        else:
            break

    if idx1 == -1: 
        if tukaeru[0] == '0':
            nedan.insert(0, tukaeru[1])
        else:
            nedan.insert(0, tukaeru[0])
        idx1 = 1
    else: 
        for item1 in tukaeru:
            if item1 > nedan[idx1]:
                nedan[idx1] = item1
                break
        idx1 = idx1 + 1

    for idx1 in range(idx1, len(nedan)):
        nedan[idx1] = tukaeru[0]

print(''.join(nedan))

Solution (Python):
N, K, *D = open(0).read().split()
N = int(N)
for i in range(N, 10*N):
    S = str(i)
    flg = True
    for s in S:
        if s in D:
            flg = False
            break
    if flg:
        print(i)
        break

Solution (Python):
n, k = input().split()
d = input().split()
valid = [i for i in range(10) if str(i) not in d]
ans = ''

if valid[-1] < int(n[0]):
    if valid[0] == 0:
        ans += str(valid[1])
    else:
        ans += str(valid[0])
    ans += str(valid[0]) * len(n)
elif valid[-1] == int(n[0]):
    for s in n:
        if s > str(valid[-1]):
            ans = str(valid[-1])
            ans += str(valid[0]) * len(n)
            break
        ans += str(valid[-1])
else:
    for i, s in enumerate(n):
        if i > 0 and ans[i-1] > n[i-1]:
            ans += str(valid[0]) * (len(n)-i)
            break

        for k in valid:
            if k >= int(s):
                ans += str(k)
                break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    D=LI()
    
    for i in range(N,10**5+1):
        ans=str(i)
        f=1
        for j in range(K):
            if str(D[j]) in ans:
                f=0
                break
            
        if f==1:
            break
        
        
    print(ans)

main()

Solution (Python):
n,k=map(int,input().split())
t=list(map(int,input().split()))
while True:
  tab=0
  for i in t:
    if str(i) in list(str(n)):
      tab+=1
  if tab==0:
    print(n)
    break
  else:
    n+=1

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

num = set(i for i in range(10))

D = num - D

for i in range(n, 100000):
    for _ in str(i):
        if int(_) not in D:
            break
    else:
        print(i)
        break

Solution (Python):
from sys import stdin

lines = stdin.readlines()
counter = []
each_line = []
for i, line in enumerate(lines):
    if i == 0:
        counter = [int(x) for x in (line.rstrip().split())]
    else:
        each_line = [str(x) for x in (line.rstrip().split())]

str_n = str(counter[0])
digit = len(str_n)

for num in range(counter[0], 100000, 1):
    num_str = str(num)
    for char in num_str:
        for dame in each_line:
            if char == dame:
                break
        else:
            continue
        break
    else:
        print(num)
        break

Solution (Python):
n, K = map(int, input().split())
d = [x for x in input().split()]

e = set(d)
ans = n

while True:
    q = set(str(ans))
    if len(q&e) == 0:
        break
    else:
        ans += 1

print(ans)

Solution (Python):
import sys

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

answer = sys.maxsize
for x in range(N, 100000):
    s = str(x)
    if all([y not in s for y in D]):
        answer = min(answer, x)
print(answer)

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())
D = set(map(str, input().split()))

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

Solution (Python):
n, k = map(int, input().split())
num_list=list(map(int,input().split()))
flag = False
num = n
while flag == False:
	str_num = str(num)
	flag = True
	for ban_num in num_list:
		if str(ban_num) in str_num:
			num = num + 1
			flag = False
			break
print(num)

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

for i in range(n, n + 100000):
  ok = True
  for j in str(i):
    if j in ds:
      ok = False
      break
  if ok:
    print(i)
    break

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

Solution (Python):
n,k =map(int,input().split())
D = set(str(x) for x in input().split())
safe = set(range(10)) - D

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(input())
restrict = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i):
	global restrict
	if not restrict:
		return min_number
	for s in range(10):
		if (str(s) not in d_ng_list) and str(s) >= n_price[i]:
			if s > int(n_price[i]):
				restrict = False
			return str(s)
	
	restrict = False
	return str(min_number+min_number)

def rec_cal_pay(answer, i, restrict):
	if i == n_length-1:
		answer += find_number(i)
		print(answer)
		return
	else:
		c = find_number(i)
		rec_cal_pay(answer+c, i+1, restrict)

rec_cal_pay(answer, 0, restrict)

Solution (Python):

n,k = map(int,input().split( ))
d= set(input().split( ))
ans = n

while True:
    tmp = set(str(ans))
    flag = True
    for e in tmp:
        if e in d:
            flag = False
            ans += 1
            break
    if flag:
        break

print(ans)

Solution (Python):
n,k=map(int,input().split())
D=input().split()
for i in range(n,10**5):
    flag=True
    S=str(i)
    for s in S:
        if s in D:
            flag=False
            break
    if flag:
    	ans=i
    	break
print(ans)

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
usenum = set()
for i in range(10):
    if not i in D:
        usenum.add(str(i))

for i in range(N, N*10+1):
    t = set(str(i))
    if t.issubset(usenum):
        print(i)
        break

Solution (Python):
N, K = map(int, input().split())
s = list(map(int, input().split()))
all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
usable = set(all) - set(s)
i = 0
while i == 0:
  num = N
  l = list(map(int, list(str(num))))
  wa = set(usable) | set(l)
  if wa == usable:
    i = i + 1
  else:
    N = N + 1
print(N)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
n,k = map(int,readline().split())

lst1 = list(readline().rstrip().decode('utf-8').split())
i = n
while True:
    flag = 0
    for j in lst1:
        if j in str(i):
            i += 1
            flag = 1
            break
    if not flag:
        print(i)
        break

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

for i in range(n,10*n+1):
  i=str(i)
  check=1
  for c in i:
    if c in d:
      check=0
  if check==1:
    print(i)
    exit()

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

for i in range(n,100001):
    x = 0
    for j in str(i):
       
        if int(j) in d:
            x = 1
            break
   
    if x == 1:
        pass
    else:
        break
print(i)

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

Solution (Python):
n,k=map(int,input().split())
d=set(input())
for i in range(n, 10000000):
  if len(set(str(i))&d)==0:
    print(i)
    break

Solution (Python):

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

use = [i for i in range(10)] 
for i in range(K): use.remove(D[i])

ans = N
while True:
    flag = True
    for item in list(str(ans)):
        if not (int(item) in use):
            flag = False
    if flag:
        break
    else:
        ans += 1

print(ans)

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

while True:
    ans = N + count
    if len(set(D) & set(list(str(ans)))) == 0:
        break
    count += 1

print(ans)

Solution (Python):
n,k=map(int,input().split())
d=list(map(str,input().split()))
while True:
    s=str(n)
    f=1
    for i in range(len(s)):
        if s[i] in d:
            f=0
    if f:
        print(n)
        exit()
    n+=1

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

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

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    
    
    N, K = [int(x) for x in sys.stdin.readline().split()]  
    h_list = [int(x) for x in sys.stdin.readline().split()]  

    
    
    
    

    logger.debug('{}'.format([]))

    for i in range(N, 10 * N):
        i_set = set([int(c) for c in str(i)])
        is_broken = False
        for d in h_list:
            if d in i_set:
                is_broken = True
                break
        if not is_broken:
            print(i)
            return


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)

Solution (Python):
N, K = map(int,input().split())
D = list(input())
for i in range(N, 100000):
    M = list(str(i))
    if all([M[j] not in D for j in range(len(M))]):
        ans = int("".join(M))
        break
print(ans)

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

ans = n
while True:
    for min in out_list:
        if min in str(ans):
            ans += 1
            break
    else:
        break

print(ans)

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


f = True
while(f):
  for s in d:
    if s in str(n):
      _ = n
      n += 1
      break
  else:
    break
print(n)

Solution (Python):
N,K=map(int,input().split())
s=''.join(list(map(str,input().split())))
while True:
    t=str(N)
    for l in t:
        if l in s:
            N+=1
            break
    if(N==int(t)):
        print(t)
        exit()

Solution (Python):
from sys import stdin
def check(n,s):
    n=str(n)
    for i in range(len(n)):
        if int(n[i]) not in s:
            return False
    else:
        return True

def main():
    
    readline=stdin.readline
    N,K=map(int,readline().split())
    D=list(map(int,readline().split()))

    s=set([0,1,2,3,4,5,6,7,8,9])
    s0=set(D)
    s1=s-s0
    M=int(str(max(s1))*(len(str(N))+1))

    for i in range(N,M+1):
        if check(i,s1):
            print(i)
            break

if __name__=="__main__":
    main()

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

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

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

Solution (Python):
def check(num, ng):
    for c in str(num):
        if int(c) in ng:
            return False
    return True
N, K = map(int, input().split())
D = set(list(map(int, input().split())))
while True:
    if check(N, D):
        print(N)
        break
    else:
        N += 1

Solution (Python):
N,K = map(int,input().split())
D = list(input().split())
for i in range(N,100001):
    n = str(i)
    k = 1
    for j in n:
        if j in D:
            k=0
            break
    if k:
        print(n)
        break

Solution (Python):
N,K=map(int,input().split())
D=[x for x in input().split()]
E=set(D)
ans=N
while True:
    q=set(str(ans))
    if (q&E)==set():
        break
    else:
        ans+=1
print(ans)

Solution (Python):
N,K=map(int,input().split())
D=[x for x in input().split()]
E=set(D)
ans=N
while True:
    q=set(str(ans))
    if len(q&E)==0:
        break
    else:
        ans+=1
print(ans)

Solution (Python):
yen, num = list(map(int, input().split()))
dislike = list(map(int, input().split()))
dislike.sort()
a = [1]*10
ans = []
yenstr = list(str(yen))
for i in range(num):
  a[dislike[i]] = 0
for i in range(10):
  if a[i] != 0:
    ans.append(i)

for i in reversed(range(len(yenstr))):
  if ans[len(ans)-1]<int(yenstr[i]):
    if i==0:
      if ans[0]==0:
        yenstr.insert(i, ans[1])
      else:
        yenstr.insert(i, ans[0])
    else:
      yenstr[i] = ans[0]
      yenstr[i-1] = int(yenstr[i-1])+1
output=0
for i in range(len(yenstr)):
  for j in range(len(ans)):
      if yen < output:
        output += ans[0]*10**(len(yenstr)-(i+1))
        break
      elif int(yenstr[i]) <= ans[j]:
        output += ans[j]*10**(len(yenstr)-(i+1))
        break
      elif j == len(ans)-1:
        output += ans[0]*10**(len(yenstr)-(i+1))

print(output)

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

for i in range(n, 100001):
    if set(list(str(i))) & d == set():
        print(i)
        break

Solution (Python):


n,k = map(int,input().split())
d = input().split()
c = True

while c:
    if all(str(n)[i] not in d for i in range(len(str(n)))):
        print(n)
        c = False
        break
    else:
        n += 1

Solution (Python):
N,K=map(int,(input().split()))
li=[]
m=set(input())
for j in range(N,100000):
    if len(set(m & set(str(j))))==0:
        print(j)
        break

Solution (Python):



def main():
  n, k = map(int, input().split())
  ds = set(input().split())
  for x in range(n, 10*n+1):
    if len(set(list(str(x))) & ds) == 0:
      print(x)
      break
    

if __name__=='__main__':
  main()

Solution (Python):
N, K = map(int, input().split())
D = list(map(str, input().split()))
for i in range(N, 100000):
    s = list(str(i))
    flg = 0
    for j in s:
        if j in D:
            flg = 1
            break
    if flg == 0:
        print("".join(s))
        break

Solution (Python):
n, k = map(int,input().split())
d = list(map(int,input().split()))
foruse = [0,1,2,3,4,5,6,7,8,9]
for item in d:
    foruse.remove(item)


for i in range(n,100000):
    flag = 1

    for item in list(str(i)):
        if int(item) not in foruse:
            flag = 0
    if flag == 1:
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
dis = [_ for _ in input().split()]
for yen in range(1, 100000):
    if yen < n:
        pass
    else:
        if len(set(list(str(yen))) & set(dis)) == 0:
            print(yen)
            exit()

Solution (Python):
n, k = map(int, input().split())
dis = [_ for _ in input().split()]
for yen in range(1, 100000):
    if yen < n:
        pass
    else:
        if len(set(list(str(yen))) & set(dis)) == 0:
            print(yen)
            exit()

Solution (Python):

n,k=map(int,input().split())
d=list(map(str,input().split()))
flg=True
while flg:
    sn=str(n)
    
    if all([sni not in d for sni in sn]):
        flg=False
    n+=1
        
print(n-1)

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









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

Solution (Python):
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]


def main():

    n,m = map(str, input().split())
    d = list(map(int, input().split()))
    use = []
    for i in range(0,10):
        if i not in d:
           use.append(str(i))
    
    ans_list = []
    for start in use:
        stack = deque()
        stack.append(start)
        ans = ''
        while stack:
            x = stack.pop()
            if int(n) <= int(x):
                ans_list.append(int(x))
            else:
                for tumu in use:
                    if len(x + tumu) <= len(n) + 1:
                        stack.append(x + tumu)

    print(min(ans_list))

if __name__ == '__main__':
    main()

Solution (Python):
line1 = input()
line2 = input()
price, k = line1.split(" ")
num = line2.split(" ")
ans = ""

for i in range(int(price),100000):
    num2 = [str(x) for x in str(i)]

    if len(set(num)&set(num2))==0:
        print(i)
        break

Solution (Python):

def dfs(i,s):
    if i==n_keta:
        if s>=n:
            kouho.append(s)
        return 0
    for j in range(len(like)):
        dfs(i+1,s+like[j])
    return 0

n,k=input().split()
d=list(map(int,input().split()))
like=[]
for i in range(10):
    if i not in d:
        like.append(str(i))
kouho=[]
n_keta=len(n)
dfs(0,"")
ans=""
if kouho==[]:
    if like[0]=="0":
        ans+=like[1]
    else:
        ans+=like[0]
    for i in range(n_keta):
        ans+=like[0]
else:
    ans=min(kouho)
print(ans)

Solution (Python):
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]


def main():

    n, k = input().split()
    d = list(map(int,input().split()))
    use = []
    for i in range(0,10):
        if i in d:
            continue
        else:
            use.append(i)

    flag = False
    for i in range(int(n),10*int(n)+1):
        number = str(i)
        for j in range(len(number)):
            if j != len(number)-1:
                if number[j] not in str(use):
                    break
            else:
                if number[j] in str(use):
                    flag = True
                else:
                    break

        if flag:
            print(i)
            break


if __name__ == '__main__':
    main()

Solution (Python):
n, k = map(int, input().split())
d = list(map(str, input().split()))
for i in range(n, 10 ** 5 + 1):
    s = list(str(i))
    c = 0
    for j in s:
        if j in d:
            c = 1
            break
    if c == 0:
        print("".join(s))
        break

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

Solution (Python):
n,k = map(int,input().strip().split())
d = list(input().split())
for x in range(n,100000):
    for y in d:
        if y in str(x):
            break
    else:
        print(x)
        break

Solution (Python):
n,k = map(int,input().strip().split())
d = list(input().split())
for x in range(n,100000):
    for y in d:
        if y in str(x):
            break
    else:
        print(x)
        break

Solution (Python):
n,k = map(str, input().split())
li = list(map(str, input().split()))
Li = list(n)
while len(set(Li)&set(li)):
  n = int(n)+1
  Li = list(str(n))
else: print("".join(Li))

Solution (Python):
N,K=input().split()
D=input().split()
E=[int(n) for n in D]

while True:
    numbers=[]
    for a in N:
        b=int(a)
        numbers.append(b)
    for c in numbers:
        if c in E:
            z = int(N)
            z += 1
            N = str(z)
            break

    else:
        print(N)
        break

Solution (Python):
n,k = map(int,input().strip().split())
d = list(input().split())
for x in range(n,100000):
    for y in d:
        if y in str(x):
            break
    else:
        print(x)
        break

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

for x in range(N, 100000):
    for y in D:
        if y in str(x):
            break
    else:
        print(x)
        break

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
while True:
  s=str(n)
  cnt=0
  for x in d:
    if x in s:
      cnt+=1
      break
  if cnt==0:
    print(n)
    exit()
  n+=1

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(int(s))
  else:
    for i in digit:
      if len(i+s) <= len(str(n))+1:
        stack.append(i+s)

print(min(ans))

Solution (Python):
N, K = map(int, input().split())
D = list(map(str, input().split()))
for i in range(N, 10**18):
  num = i
  i = str(i)
  for j in range(len(str(num))):
    if i[-1] in D:
      num=0
      break
    else:
      i = i[:-1]
      continue
  if num:
    print(num)
    break

Solution (Python):
line1 = input()
line2 = input()
price, k = line1.split(" ")
num = line2.split(" ")
ans = ""

for i in range(int(price),100000):
    num2 = [str(x) for x in str(i)]

    if len(set(num)&set(num2))==0:
        print(i)
        break

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

D = set(D)

while True:
    S = str(N)
    for s in list(S):
        if int(s) in D:
            N += 1
            break
    else:
        break
    continue
print(N)

Solution (Python):
a = input().split()
N = int(a[0])
K = int(a[1])

a = input().split()

def check(v):
    s = set(str(v))
    return s == s-set(a)

def solve():
    v = N
    while not check(v):
        v += 1
    return v

print(solve())

Solution (Python):
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int,input().split())
    D = set(input().split())
    for ans in range(N,1000000):
        f = 0
        for e in str(ans):
            if e in D:
                f = 1
                break
        if f == 0:
            print(ans)
            exit(0)
if __name__ == '__main__':
    main()

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

while True:
    for s in D:
        if N.count(s)!=0:
            frag=1

        else:
            pass
    if frag==1:
        a=int(N)+1
        N=str(a)

    else:
        break

    frag=0

print(N)

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

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


for i in range(n, n+100000000):
    if len(set(str(i)) & set(A)) == 0:
        print(i)
        break

Solution (Python):
def main():
    cost, dislike = map(int, input().split())
    dislike_numbers = list(input().split())
    answer = cost
    while True:
        if not set(str(answer)) & set(dislike_numbers):
            print(answer)
            break
        else:
            answer += 1


if __name__ == '__main__':
    main()

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

    while True:
        s=set(str(n))
        flag=True
        for i in s:
            if i in d:
                flag=False
                break
        if flag:
            break
        else:
            n+=1       
    print(n)               
if __name__=='__main__':
    main()

Solution (Python):
n,k = map(int,input().split())
l = list(input().split())
for i in range(n,n+100001):
    check = True
    
    for j in list(str(i)):
        if j in l:
            check = False 
    if check:
        print(i)
        exit()

Solution (Python):
import sys
n,k=map(int,input().split())
d=set(input().split())
for i in range(n,99999+1):
  flag=True
  s=str(i)
  for j in s:
    if j in d:
      flag=False
      break
  if flag:
    print(i)
    sys.exit()

Solution (Python):
import sys
if __name__ == '__main__':
    N,K= map(int, input().split())
    bads=[int(x) for x in input().split()]
    nums=[i for i in range(10)]
    nums=list(set(nums)-set(bads))
    nums_set=set(nums)
    yen=N
    
    flag=1
    while flag:
        yen_set=set([int(x) for x in str(yen)])
        if yen_set <= nums_set:
            print(yen)
            flag=0
        else:
            yen += 1

Solution (Python):
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = sorted(list(num_set.difference(set(D))))

if (list(set(D)&set(N_list)) == []):
    print(N)
else:
    if '0' in diff_list:
        n_list = [diff_list[1]] + ['0']*len(N_list)
    else:
        n_list = [diff_list[0]]*(len(N_list)+1)
    str_n = ''
    for i in n_list:
        str_n += str(i)
    new_n = int(str_n)+1
    for ii in range(N, new_n):
        if list(set(list(str(ii)))&set(D)) == []:
            print(ii)
            break

Solution (Python):



n, k = input().split()
d = input().split()
while True:
    if len(set(n) & set(d)) == 0:
        print(n)
        break
    n = str(int(n) + 1)

Solution (Python):



n, k = [int(x) for x in input().split()]
d = [x for x in input().split()]
while True:
    if len(set(str(n)) & set(d)) == 0:
        print(n)
        break
    n += 1

Solution (Python):


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

ans = n
b = n
while (1):

    c = True
    b = n
    while (b != 0):
        d = b % 10
        b = b // 10

        if d in a:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)

Solution (Python):
import sys

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

for n in range(N, 10**9):
  li = list(str(n))

  for i in li:
    if int(i) in D:
      break

  else:
    print(n)
    sys.exit()

Solution (Python):
import bisect
n,k=map(int,input().split())
num_list=[i for i in range(10)]
d=list(input().split())
ans=n
while(True):
	n_digit=str(ans)
	for i in range(len(d)):
		if d[i] in n_digit :
			break
	else:
		print(ans)
		exit()
	ans+=1

Solution (Python):



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


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

while True:
  
  digit_set = set(map(int,str(N)))
  
  if len(D & digit_set) == 0 :
    break
  N += 1

print(N)