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


if __name__ == "__main__":
    n, k = input().split()
    hate = input() if k == 1 else [x for x in input().split()]
    like = [str(x) for x in range(0, 10) if str(x) not in hate]

    found = False
    while not found:
        for i in range(len(n)):
            if len(like) < len(hate):
                if i == len(n) - 1 and n[i] in like:
                    found = True
                    break
                elif n[i] not in like:
                    break
            else:
                if i == len(n) - 1 and n[i] not in hate:
                    found = True
                    break
                if n[i] in hate:
                    break
        if not found:
            n = str(int(n) + 1)
    print(n)

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

ans = n
flag = True
while flag:
    flag = False
    for i in d:
        if str(ans).count(i) != 0:
            flag = True
            ans += 1
            break
print(ans)

Solution (Python):
import collections

n, k = map(int, input().split())
counter = collections.Counter(list(map(int, input().split())))
for i in range(n, 100000):
    ok = True
    x = i
    while x > 0:
        ok = counter[x % 10] == 0
        x //= 10
        if not ok:
            break
    if ok:
        print(i)
        break

Solution (Python):
def check(x, d):
    str_x = str(x)
    for s in str_x:
        if s in d:
            return False
    return True


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

for x in range(n, 10**10):
    if check(x, d):
        print(x)
        exit()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n, k = map(int, input().split())
    d = set(map(int, input().split()))
    safe = set(range(10)) - d

    def test(n):
        return set(int(x) for x in str(n)) <= safe

    def f(n):
        while n % 10:
            if test(n):
                return n
            n += 1
        x = f(n//10)
        y = min(safe)
        return 10 * x + y

    ans = f(n)
    print(ans)


   


if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(N: int, K: int, D: "List[int]"):
    d = set(map(str, D))
    while set(str(N))&d:
        N += 1

    print(N)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    D = [int(next(tokens)) for _ in range(K)]  
    solve(N, K, D)

if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(N: int, K: int, D: "List[int]"):
    
    while(True):
        nl = list(map(int,list(str(N))))
        f = True
        for i in range(len(nl)):
            if(nl[i] in D):
                f = False
        if(f):
            print(N)
            exit()
        else:
            N += 1

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    D = [int(next(tokens)) for _ in range(K)]  
    solve(N, K, D)

if __name__ == '__main__':
    main()

Solution (Python):
def check(price, disabled_digits):
    price = int(price)
    disabled_digits = set(disabled_digits)
    while not set(str(price)).isdisjoint(disabled_digits):
        price += 1
    return price


def main():
    price, k = input().split()
    disabled_digits = input().split()
    print(check(price, disabled_digits))


if __name__ == '__main__':
    main()

Solution (Python):
class Price:
    ALL_DIGITS = set(list(map(str, range(10))))

    def __init__(self, required_price, disabled_digits):
        self.required_price = '0' + str(required_price)
        self.disabled_digits = set(disabled_digits)
        self.available_digits = sorted(
            list(self.ALL_DIGITS - self.disabled_digits))
        self.payed_price = required_price

    def get_greater_digit(self, digit):
        candidates = [d for d in self.available_digits if d >= digit]
        if len(candidates) == 0:
            raise ValueError
        return min(candidates)

    def get_lower_digit(self, digit):
        candidates = [d for d in self.available_digits if d <= digit]
        if len(candidates) == 0:
            raise ValueError
        return max(candidates)

    def _from_right(self):
        reversed_price = list(reversed(self.required_price))
        length = len(reversed_price)
        for i in range(length - 1):
            r = reversed_price[i]
            if r not in self.available_digits:
                try:
                    reversed_price[i] = self.get_greater_digit(r)
                except ValueError:
                    reversed_price[i] = min(self.available_digits)
                    r_next = reversed_price[i + 1]
                    reversed_price[i + 1] = chr(ord(r_next) + 1)

        r = reversed_price[-1]
        if r not in self.available_digits and r != '0':
            reversed_price[-1] = self.get_greater_digit(r)

        self.payed_price = ''.join(reversed(reversed_price))

    def _from_left(self):
        carry = False
        i = 0
        pay = list(self.payed_price)
        while i < len(pay):
            if carry:
                pay[i] = min(self.available_digits)
            else:
                carry = pay[i] > self.required_price[i]
            i += 1
        self.payed_price = ''.join(pay)

    def calculate(self):
        self._from_right()
        self._from_left()

    def get_payed_price(self):
        return int(self.payed_price)


def check(price, disabled_digits):
    p = Price(required_price=price, disabled_digits=disabled_digits)
    p.calculate()
    return p.get_payed_price()


def main():
    price, k = input().split()
    disabled_digits = input().split()
    print(check(price, disabled_digits))


if __name__ == '__main__':
    main()

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

for i in range(N,100000):
    if set(str(i)) & D == set():
        print(i)
        break

Solution (Python):
def main():
    N, K = map(int, input().split())
    lst_D = list(input().split())

    cost = N
    while True:
        for c in str(cost):
            if c in lst_D:
                break
        else:   
            print(cost)
            break
        cost += 1


if __name__ == "__main__":
    main()

Solution (Python):
def judge(lst_D, number):
    str_number = str(number)
    for d in lst_D:
        if d in str_number:
            return False
    return True


def main():
    N, K = map(int, input().split())
    lst_D = list(input().split())

    cost = N
    while True:
        if judge(lst_D, cost):
            print(cost)
            break
        cost += 1


if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
D = {str(i) for i in range(0,10)} - set(input().split())
for i in range(N, 10 * N):
  num = set(str(i))
  if num <= D:
    print(i)
    break

Solution (Python):
n, k = map(int, input().split())
d = list(set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(map(int, input().split())))
for i in range(10-k):
    d[i] = str(d[i])

for i in range(n, 10 ** 10):
    f = 0
    for j in range(len(str(i))):
        if str(i)[j] in d:
            f += 1
        if f == len(str(i)):
            print(i)
            exit()

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

if int(len(str(K)) * str(L[-1])) < K:
    if L[0] != 0:
        print(str(L[0]) * (len(str(K)) + 1))
    else:
        print(str(L[1]) + len(str(K)) * str(L[0]))
else:
    for i in range(10 ** (len(str(K)) - 1), 10 ** len(str(K))):
        if i >= K:
            k = str(i)
            for j in k:
                if int(j) not in L:
                    break
            else:
                print(i)
                exit()

Solution (Python):
N, K = map(int,input().split())
num_list =[]
num_list = input().split()
use_num = [s for s in ["0","1","2","3","4","5","6","7","8","9"] if s not in num_list]
flag = False
answer = []

for i in range(1,len(str(N))+1):
    tmp = str(N)[-i]
    if(flag):
        flag=False
        if(tmp==str(9)):
            answer.insert(0,use_num[0])
            flag =True
            continue
        else:
            tmp = str(int(tmp) + 1)

    if(tmp in num_list):
        answer.clear()
        for j in range(i-1):
            answer.insert(0,use_num[0])
    else:
        answer.insert(0,tmp)
        
    while(tmp in num_list):
        if(tmp==str(9)):
            flag =True
            answer.insert(0,use_num[0])
            if(i==len(str(N))):
                if(use_num[0]==str(0)):
                    answer.insert(0,use_num[1])
                else:
                    answer.insert(0,use_num[0])
            break
        else:
            tmp = str(int(tmp) + 1)
            if(tmp in use_num):
                answer.insert(0,tmp)

print("".join(answer))

Solution (Python):
n,k = map(int, input().split())
d = set(list(map(str, input().split())))
cost = n
while True:
    li = list(str(cost))
    if all(i not in d for i in li):
        break
    else:
        cost += 1
print(cost)

Solution (Python):
n, k = map(int, input().split())
d_array = [str(x) for x in input().split()]
price = 0 
while True:
    flag = True
    for s in str(price):
        if s in d_array:
            flag = False
    if price >= n and flag:
        print(price)
        break
    price+=1

Solution (Python):









n, k = input().split()
d = input().split()
ans = []
while True:
    if all(map(lambda x: x not in d, n)):
        print(n)
        break
    else:
        n = str(int(n) + 1)

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
ans = N
while ans <= 10**6:
  flg = True
  for i in range(len(str(ans))):
    if int(str(ans)[i]) in D:
      flg = False
  if flg == True:
    print(ans)
    exit()
  else:
    ans += 1

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

while True:
    m = str(n) 
    found = True
    for i in range(len(m)):
        if m[i] in t:
            found = False
    if found: break
    n += 1
print(n)

Solution (Python):
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
D = [(x) for x in stdin.readline().rstrip().split()]

for i in range(N,N+10**7):
    if not (set(str(i)) & set(D)):
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
num_list = list(map(str, input().split()))
ans = n
flg = False
while flg == False:
  flg = True
  for i in str(ans):
    if i in num_list:
      flg = False
      ans += 1
      break
print(ans)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
OK = {str(x) for x in range(10)} - D
while True:
    if set(str(N)) <= OK:
        ans = N
        break
    else:
        N += 1
print(ans)

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

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

Solution (Python):
def c_iroha_obsession():
    
    N, K = [int(i) for i in input().split()]
    D = set(input().split())
    for ans in range(N, 10 * N + 1):
        if set(str(ans)) & D == set():
            return ans  
    return None

print(c_iroha_obsession())

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

for i in range(0,10):
  if i not in D:
    C.append(i)


for i in range(N,10**10):
  cnt=0
  for j in list(map(int,list(str(i)))):
    if j in C:
      cnt+=1
  if len(str(i))==cnt:
    print(i)
    exit()

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

pay = n

while True:
    dislike = False
    for ele in d:
        if ele in str(pay):
            dislike = True
            break

    if dislike:
        pay += 1
    else:
        break

print(pay)

Solution (Python):
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Solution (Python):

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


d_list = map(int, input().split())

d_set = set(d_list)

num_set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}


fav_num = d_set ^ num_set




for pay in range(N, 10*N):
	num_N = list(map(int, str(pay)))
	num_Ns = set(num_N)
	
	if num_Ns <= fav_num:
		print(pay)
		break
	
	else:
		pay = pay + 1

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

for i in range(N, 10**5):
    if set(str(i)) & D == set():
        print(i)
        exit()

Solution (Python):
n, k = map(int, input().split())
d = set(input().split())
like = set(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]) - d

for i in range(n, 100000):
    used = set(str(i))
    if used <= like:
        ans = i
        break

print(ans)

Solution (Python):
N, K = tuple(map(int, input().split()))
D = list(map(int, input().split()))
set_D = set(D)
i = N
while True:
    tmp_set = set([int(c) for c in str(i)])
    if len(set_D.intersection(tmp_set)) > 0:
        i += 1
        continue
    else:
        break
print(i)

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

ok = [True]*10

d = [int(s) for s in input().split()]

for i in d:
    ok[i] = False

ans = 0
for i in range(N, 10*N+1):
    j = i
    while j > 0 and ok[j%10]:
        j //= 10
    if j == 0:
        ans = i
        break

print(ans)

Solution (Python):
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                try:
                    return n[0]+search_min(n[1:],like)
                except TypeError:
                    return None
            else:
                j=like.index(n[0])
                if j+1<len(like):
                    return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
if search_min(N,like)==None:
    n=len(str(N))
    k="1"+"0"*n
    print(search_min(k,like))
else:
    print(search_min(N,like))

Solution (Python):


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

E = [0] * 20
for i in D:
    j = int(i)
    E[j] = 1
    E[10 + j] = 1



F = [0] * 10
r = 0
for l in range(10):
    
    while l > r or E[r] == 1:
        r += 1
    F[l] = r-l



for i in range(10):
    if F[i] == 0:
        min_ok = i
        break



ke2 = 0
i = 0
sn = str(n)
while i < len(sn):
    l = len(sn)
    
    d = l-1-i
    
    if F[int(sn[d])] != 0:
        n += int(str(F[int(sn[d])]) + "0" * i)
        
        for j in range(ke2, i):
            d2 = l-1-j
            n -= int(str(int(sn[d2]) - min_ok) + "0" * j)
            
            
    sn = str(n)
    i += 1
    

print(n)

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

use_d = []
for i in range(10):
  if i not in l:
    use_d.append(i)

use_d.sort()

m = str(n)

ds = []

import itertools
for i in itertools.product(use_d, repeat=len(m)):
  d = int("".join(str(x) for x in i))
  ds.append(d)
ds.sort()

import bisect
x = bisect.bisect_left(ds, n)
if x != len(ds):
  ans = ds[x]
else:
  ans = ''
  for i in range(len(m)+1):
    if i == 0:
      if use_d[0] == 0:
        ans += str(use_d[1])
      else:
        ans += str(use_d[0])
    else:
      ans += str(use_d[0])
  ans  = int(ans)
print(ans)

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

use_d = []
for i in range(10):
  if i not in l:
    use_d.append(i)

use_d.sort()

m = str(n)

ds = []

import itertools
for i in itertools.product(use_d, repeat=len(m)):
  d = int("".join(str(x) for x in i))
  ds.append(d)
ds.sort()

import bisect
x = bisect.bisect_left(ds, n)
if x != len(ds):
  ans = ds[x]
else:
  ans = ''
  for i in range(len(m)+1):
    if i == 0:
      if use_d[0] == 0:
        ans += str(use_d[1])
      else:
        ans += str(use_d[0])
    else:
      ans += str(use_d[0])
  ans  = int(ans)
print(ans)

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

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

INF = 10**9
ans = INF
def dfs(price):
    if price > 10*N: return INF

    if not D & set(map(int, list(str(price)))):
        return price

    return dfs(price + 1)

ans = min(ans, dfs(N))
print(ans)

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

n,k=map(int,input().split())
d=list(input().split())
for _ in range(n,100000):
    string=str(_)
    check=0
    for i in string:
        if i in d:
            check=1
    if check==0:
        print(_)
        break

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

def main():
    N, K = map(int, input().split())
    d = set(input().strip().split())

    tmp = N
    while True:
        s = set(list(str(tmp)))
        if len(s & d) == 0:
            print(tmp)
            break
        tmp += 1

if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int, input().split())
d = {str(x) for x in input().split()}
a = {str(x) for x in range(10)}
l = a - d

while True:
    if all(j in l for j in str(n)):
        print(n)
        break
    else:
        n += 1

Solution (Python):
def resolve():
    n, k = map(int, input().split())
    d = list(input().split())
    l = len(str(n))
    for i in range(n, 10 * n + 1):
        if all(c not in d for c in str(i)):
            print(i)
            return 0


if __name__ == "__main__":
    resolve()

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
d = inpl()
d = set(d)
for i in range(n,10**7):
    flag = True
    t = i
    while i:
        tmp = i%10
        if tmp in d:
            flag = False
        i = i//10
    if flag:
        print(t)
        break

Solution (Python):
N, K = map(int, input().split())
sample = [1*i for i in range(10)]
D = list(map(int,input().split()))

sa = set(sample) - set(D)
sa_list = list(sa)

total_fee = N
while 1:
    list_total_fee = list(map(int, str(total_fee)))
    if set(list_total_fee).issubset(sa_list):
        print(total_fee)
        exit(0)
    else:
        total_fee += 1

Solution (Python):
n, k = map(int, input().split())
d = {str(x) for x in input().split()}
a = {int(x) for x in range(10)}
l = a - d

for i in range(n,100000+1):
    i2 = str(i)
    for j in range(len(i2))[::-1]:
        if i2[j] in d:
            break
    else:
        print(i2)
        break

Solution (Python):
n, k = map(int, input().split(" "))
list_k = list(map(int, input().split(" ")))
list_use_num = []
for i in range(10):
  if i not in list_k:
    list_use_num.append(i)
check_num = n
while True:
  list_check_num = list(map(int, str(check_num)))
  if set(list_check_num).issubset(list_use_num):
    print(check_num)
    break
  else:
    check_num += 1

Solution (Python):
n,k=map(int,input().split())
D=list(map(int,input().split()))
for i in range(n,100*n):
    if all([int(x) not in D for x in str(i)]):
        print(i)
        exit()

Solution (Python):
def is_OK(i, not_dislike):
    dig_OK = []
    tmp = str(i)
    i_list = [int(tmp[j]) for j in range(len(tmp))]
    for l in i_list:
        if l in not_dislike:
            dig_OK.append(True)
        else:
            dig_OK.append(False)
    return all(dig_OK)

N, K = list(map(int, input().split()))
D = [int(a) for a in input().split()]
not_dislike = []
for i in range(10):
    if i not in D:
        not_dislike.append(i)
for i in range(N, 10 * N + 1):
    if is_OK(i, not_dislike):
        print(i)
        break

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

for i in range(n,10*n):
  str_i=str(i)
  if all(int(j) not in d for j in str_i):
    ans = i
    break
print(ans)

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

c = list(range(10))


while n:
    a = list(str(n))
    if list(filter(lambda x: int(x) in d, a)) == []:
        break
    n += 1
print(n)

Solution (Python):

N,K = map(int,input().split())
lst = list(map(str,input().split()))
ans = 0
while True:
    flag = len(list(set(lst) & set(list(str(ans)))))
    if ans >= N and flag == 0:
        break
    ans += 1
print(ans)

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

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

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

ans = 10**6

for i in range(10**6):
    if ans != 10**6:
        break
    cnt = i
    if n > cnt:
        continue
    while cnt != 0:
        if cnt % 10 in d:
            break
        if cnt < 10:
            ans = i
            break
        cnt = cnt // 10
            
print(ans)

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

temp=N
f=False
while f==False:
    num=set(list(str(temp)))
    f=True
    for i in num:
        if i in D:
            f=False
            break
    if f==True:
        print(temp)
        exit()
    temp+=1

Solution (Python):
c = 0
f = True
N, K = map(int, input().split())
ld = list(map(str, input().split()))
while f:
    i = 0
    N_str = str(N)
    for i in range(K):
        
        if ld[i] in N_str:
            N += 1
            break
        elif i == K-1:
            f = False
print(N)

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

possible = False
while not possible:
    n_str = str(n)
    possible = True
    for di in d:
        if di in n_str:
            possible = False
            n += 1
            break

print(n)

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

value = n

while(1):
    value_list = [s for s in str(value)]
    flag = 0

    for i in d:
        if i in value_list:
            flag = 1
            break

    if flag:
        value += 1
    else:
        break

print(value)

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

ans=0

for i in range (n,100000):
  s= str(i)
  
  pay=True
  
  for j in range (len(s)):
    
    if s[j] in d:
      pay = False
      break
    
    
  if pay:
      ans = i
      break
print(ans)

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

ans = 0
for i in range(n,100000):
    s = str(i)
    pay = True
    for j in range(len(s)):
        if s[j] in d:
            pay = False
            break
    if pay:
        ans = i
        break
print(ans)

Solution (Python):
n,k=map(int,input().split())
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                r=10**(q-c-1)
                n=int(n/r+1)*r
                t=1
                break
    if t==0:
        break
print(n)

Solution (Python):
n,k=map(int,input().split())
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+1
                t=1
                break
    if t==0:
        break
print(n)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
flag=0
B=[0]*10
for i in range(len(A)):
    B[A[i]]+=1
for i in range(N,100000):
    flag = 0
    k = str(i)
    for j in range(len(k)):
        if B[int(k[j])]==1:
            flag=1
    if flag==0:
        print(k)
        exit(0)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
flag=0
B=[0]*10
for i in range(len(A)):
    B[A[i]]+=1
for i in range(N,100000):
    flag = 0
    k = str(i)
    for j in range(len(k)):
        if B[int(k[j])]==1:
            flag=1
    if flag==0:
        print(k)
        exit(0)

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

d = list(input().split())


def check(kakaku, negative_number):
  check_sum = 1
  for i in negative_number:
    if i in str(kakaku):
      
      check_sum = 0
      break
    else:
      pass
  return check_sum

while check(n, d) == 0:
  n += 1

print(n)

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

usable = set(range(10)) - set(d)

while True:
    if {int(i) for i in set(list(str(n)))} <= usable:
        print(n)
        exit()
    else:
        n += 1

Solution (Python):
a,b = map(int,input().split()) 
li1 = set(map(int,input().split()))
li2 = {1,2,3,4,5,6,7,8,9,0}
nu = list(li1^li2)

i = 1
while True:
    aa = list(str(a))
    aa = [int(x) for x in aa]
    if set(aa).issubset(set(nu)):
        print(a)
        break
    a += i

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

num = N
flag = True

while flag:
    for i in D:
        if str(i) in str(num):
            num += 1
            break
    else:
        print(num)
        flag = False

Solution (Python):
import sys

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

D_ava = list(map(str,[i for i in range(1,10) if i not in D]))
for s in range(N, 10**5+1):
	ss = list(set(str(s)))
	cond = True
	for sss in ss:
		if sss in D:
			cond = False
			break
	if cond == True:
		print(s)
		sys.exit()
	else:
		continue

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
ans=n
while 1:
  hoge=list(str(ans))
  flag=0
  for i in range(len(l)):
    flag+=hoge.count(str(l[i]))
  if(flag==0):
    print(ans)
    exit()
  ans+=1

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

d = [i for i in range(10)]
din = list(map(int,input().split()))

for i in din:
    d.remove(i)

flg = 0

for i in range(n,100000):
    for j in range(len(din)):
        
        if str(din[j]) in str(i):
            flg=1
            break
    if flg == 0:
        print(i)
        break
    else:
        flg=0

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

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

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

d = input().split()

while True:
  not_in = True
  for i in range(k):
    if d[i] in str(n):
      not_in = False
      break
  if not_in:
    print(n)
    break
  n += 1

Solution (Python):
import sys

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

for i in range(N, 10 ** 7):
    ansb = True
    for j in d:
        if str(i).count(str(j)) != 0:
            ansb = False
            break
    if ansb:
        print(i)
        sys.exit()

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

isNotMin = True

temp = N * 1

while isNotMin:
    for i in str(temp):
        if int(i) in D:
            temp += 1
            isNotMin = True
            break
        else:
            isNotMin = False

print(temp)

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

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

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







i=0
result=[]









flag=False
while flag == False :
    
    for i in range(len(str(N))):
        if int(str(N)[i]) in array:
            break
    else:
        flag=True

    N+=1

print(N-1)

Solution (Python):
def f(S):
  SS = str(S)
  for d in D:
    if d in SS:
      return True
  return False

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

while f(N):
  N += 1

print(N)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools,pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
D = LI()
nums = [str(i) for i in range(0, 10) if i not in D]

"""
使える数字の中で一番低いものから試していく
見つかったら各桁試していく

"""

all_nums = []
for i in range(N, 99999):
    
    all_nums.append(i)
for num in all_nums:
    if num >= N:
        if all(i in nums for i in str(num)):
            print(num)
            exit()

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

while not set(N).isdisjoint(D):
    N=str(int(N)+1)
else:
    print(N)