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



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Accepted

Solution code:
# At BC 042 C (300)

# find first digit (from the left)
# that needs to be changed.
# if that digit is incremented, then
#   decrement everything after it as much as possible
# if that digit has to be decremented, then increase (or insert) a digit
#   before that digit and then decrement everything after the incremented digit
#
def dec(i, D):
    for k in range(i - 1, -1, -1):
        if k not in D:
            return k
    return i

def inc(i, D):
    for k in range(i + 1, 10):
        if k not in D:
            return k
    return i

def max_dec_or_inc(A, start, D):
    for j in range(start, len(A)):
        d = dec(A[j], D)
        if d != A[j]:
            while d != A[j]:
                A[j] = d
                d = dec(A[j], D)
        elif A[j] in D: # must change
            u = inc(i, D)
            A[j] = u

def inc_one(A, end, D):
    for j in range(end - 1, -1, -1):
        up = inc(A[j], D)
        if up != A[j]:
            A[j] = up
            return j
    A.insert(0, inc(0, D))
    return 0

def f(n, D):
    out = list(map(int, str(n)))
    for j, i in enumerate(out):
        if i in D: # first from left that needs to be changed
            up = inc(i, D)
            if up != i: # possible to increment at j
                out[j] = up
                # decrement everything after j
                max_dec_or_inc(out, j + 1, D)
            else: # must decrement at index j
                out[j] = dec(i, D)
                # increment one before j
                idx = inc_one(out, j, D)
                # decrement everything after j
                max_dec_or_inc(out, idx + 1, D)
            break
    r = int("".join([str(x) for x in out]))
    return r

assert f(1000, [1, 3, 4, 5, 6, 7, 8, 9]) == 2000
assert f(9999, [0]) == 9999
assert f(6888, [8, 9]) == 7000
assert f(9999, [9]) == 10000
assert f(9999, [0, 9]) == 11111
assert f(9999, [0, 1, 9]) == 22222

n, k = map(int, input().split())
D = list(sorted(map(int, input().split())))
ans = f(n, D)
print(ans)

Submission status: Accepted

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

n = set(str(N))
ans = N
while True:
    for t in n:
        if t in D:
            break
    else:
        print(ans)
        exit()
    ans += 1
    n = set(str(ans))

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin
N, K = F.readline().rstrip().split()
N = int(N)
K = int(K)
D = list(map(str,F.readline().rstrip().split()))

answer = None

# pdb.set_trace()

while answer is None:
    Nstr = str(N)
    for i in range(len(Nstr)):
        if Nstr[i] in D:
            N += 1
            break

        if i == len(Nstr) - 1:
            answer = N

print(answer)

Submission status: Accepted

Solution code:


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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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:   # break しなかったときのみ実行される
            print(cost)
            break
        cost += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
# ダサい解き方だが桁上がり等を考えてややこしい実装をして間違うよりは良い

# def check_digit(v, d):
#     if v in d:
#         # if v == '9':            
#         return check_digit(str(int(v) + 1), d)
#     else:
#         return v

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)
# for v in sorted(n, reverse=True):
#     ans.append(check_digit(v, d))

# print(''.join(ans))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
def c_iroha_obsession():
    # 1種しか使えない場合でも、Nの桁数+1だけ並べればいい。2種以上ならより小さい
    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  # ansが含む数字の集合とDの合併が空集合なら条件を満たす
    return None

print(c_iroha_obsession())

Submission status: Accepted

Solution code:
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)
#print(C)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#N円の品物、K個の嫌いな数字
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

#N ~ 10Nの間の数字で、fav_numの中の数字のみから作られる
#payを1つずつ探す

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# O(k + log(n))

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

# print(E)

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

# print(F)

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

# print(min_ok, "min")

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

print(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

c = list(range(10))
#num = list(filter(lambda x: x not in d, c))

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

Submission status: Accepted

Solution code:
#C
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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):
        # print(i)
        if ld[i] in N_str:
            N += 1
            break
        elif i == K-1:
            f = False
print(N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
# ans を用意する
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
    #各桁がd にあるか調べて、あったら break
    
  if pay:
      ans = i
      break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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