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:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    N, K = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

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

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC042

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n,100000):
    flag = 1
#    print('test:'+str(i))
    for item in list(str(i)):
        if int(item) not in foruse:
            flag = 0
    if flag == 1:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#print(D)
#print(set(str(N)))

#&はどちらも満たすとき
#N&Dは、NとDのどちらのリストにもある要素
#print(set(str(N))&D)

#NとDの共通要素がある間はNに数字を足す
while set(str(N))&D:
  N+=1
print(N)

Submission status: Accepted

Solution code:
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()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
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)]  # NumberGrid
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))
    #print(use)
    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()

Submission status: Accepted

Solution code:
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)]
#     print(len(set(num)&set(num2)))
    if len(set(num)&set(num2))==0:
        print(i)
        break

Submission status: Accepted

Solution code:
#abc 042 c
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)

Submission status: Accepted

Solution code:
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()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
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)]  # NumberGrid
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)]
#     print(len(set(num)&set(num2)))
    if len(set(num)&set(num2))==0:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
    #print(nums_set, set([ int(x) for x in str(yen)]))
    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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# /usr/bin/env python3
# https://atcoder.jp/contests/abc042/tasks/arc058_a

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

Submission status: Accepted

Solution code:
# /usr/bin/env python3
# https://atcoder.jp/contests/abc042/tasks/arc058_a

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

Submission status: Accepted

Solution code:
#!/use/bin/env python3

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C - こだわり者いろはちゃん

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

#input D1 ~ Dk as set D
D = set(map(int,input().split()))

while True:
  #整数Nの桁に含まれる整数の集合 set digit_set
  digit_set = set(map(int,str(N)))
  #共通部分が空
  if len(D & digit_set) == 0 :
    break
  N += 1

print(N)

Submission status: Accepted

Solution code:
from itertools import product

N, K = map(int, input().split())
D = list(map(int, input().split()))
L = []
for i in range(10):
	if not i in D:
		L.append(i)
keta = len(str(N))
flg = 0

# 与えられた桁と同じ桁数で終わるとき
for num in product(L, repeat = keta):
	num = list(num)
	num.reverse()
	# print(num)
	val = 0
	for i in range(keta):
		val += num[i] * (10 ** i)
	if val >= N:
		flg = 1
		break
		
if flg:
	print(val)
# 与えられた桁で終わらないとき
else:
	for l in L:
		if l != 0:
			a = l
			break
	val = a * (10 ** (keta))
	for i in range(keta):
		val += min(L) * (10 ** i)
	print(val)

Submission status: Accepted

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

for i in range(n,100000):
    sn=str(i)
    ok=True
    for num in sn:
        if int(num) in d:
            ok=False
    if ok:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
for i in range(10 ** 5):
  if set(map(int, str(n + i))) & D:
    continue
  print(n + i)
  break

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(str,input().split()))
for k in range(9*N):
    N += 1
    for j in range(len(str(N-1))):
        if str(N-1)[j] in D:
            break
    else:
        print(N-1)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):    
    D = list(map(str,D))
    while True:
        for d in D:
            if d in str(N):
                N += 1
                break
        else:
            print(N)
            break

    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))  # 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:
N, K = map(int, input().split())
D = set(input())
while True:
    if D & set(str(N)):
         N += 1
         continue
    else:
        print(N)
        break

Submission status: Accepted

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

while True:
    for c in str(n):
        if c in d:
           break
    else:
        print(n)
        exit()
    n +=1
print(n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
list_num = [i for i in input().split()]
price = n
while True :
    i = 0
    for i in range(len(str(price))) :
        if str(price)[i] in list_num :
            price += 1
            break
    else :
        print(price)
        break

Submission status: Accepted

Solution code:
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

#@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)
    return "10" + func(s, i+1, over=True)

def solve(N, D):
    D = set(list(D))
    while True:
        ok = True
        for c in str(N):
            if c in D:
               ok = False
               break
        if ok:
            return N
        N+=1

print(solve(N, D))
#print(func(str(N), 0, over=False))

Submission status: Accepted

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


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

    while True:
        if all([True if n not in D else False for n in list(str(N))]):
            break
        N += 1
    print(N)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = n
while 1:
    for i in str(ans):
        if i in l:
            break
    else:
        break
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
numbers = [str(e) for e in range(10)]
n, k = map(int, input().split())
hate_list = [e for e in input().split()]
available = set(numbers) - set(hate_list)
for i in range(n, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()
d_s = set(D)
moto = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
amari = d_s & moto
l = list(str(N))
l = map(int, l)

# for i in range(len(l)):
i = N
while 1:
    
    l = list(str(i))
    l = list(map(int, l))
    l_s = set(l)
    s_intersection = d_s & l_s
    
    if len(s_intersection) == 0:
        print(i)
        exit()
    i += 1
    # if d_s.isdisjoint(l_s):
    #     print(i)
    #     exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d_k = set(map(int, input().split()))
ans = n
while ans <= n * 10:
    isOK = True
    for x in range(len(str(ans))):
        if int(str(ans)[x]) in d_k: 
            isOK = False
            break
    if isOK == True: break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().rstrip().split()))
d = list(map(int, input().rstrip().split()))
ans = n
while (True):
    x = ans
    flag = 1
    while x > 0:
        r = x % 10
        x = x // 10
        if r in d:
            ans += 1
            flag = 0
            break
    if flag == 1:
        break
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n))
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


if dfs(0, 0) != inf:
    print(dfs(0, 0))
else:
    stop += 1
    print(dfs(0, 0))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,_ = map(int,input().split())
ds = list(input().split())

amount = n
while 1:
  s_amount = str(amount)
  for d in s_amount:
    if d in ds:
      break
  else:
    break
  amount += 1
print(amount)

Submission status: Accepted

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

for i in range(n,10**6+1):
    s = str(i)
    for j in d:
        if j in s:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dl = set(input().split())

for i in range(n, 100000):
    if set(str(i)).intersection(dl) == set():
        print(i)
        break