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:
n, k = map(int, input().split())
D = list(map(int, input().split()))
D = set(D)

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

Submission status: Accepted

Solution code:
import itertools

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

for i in itertools.count(n):
    for k in str(i):
        if k in d:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    D = Scanner.string().split(sep=' ')
    ans = N
    while True:
        for s in str(ans):
            if s in D:
                break
        else:
            print(ans)
            return
        ans += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
D = set(input().split())
num = {str(i) for i in range(10)} - D

while True:
    if set(str(N)) <= num:
        ans = N
        break
    else:
        N += 1
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
ans = N
while not set(str(ans)).isdisjoint(D):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
List = list(input().split())
Digit = ['0','1','2','3','4','5','6','7','8','9']
for item in List:
  if item in Digit:
    Digit.remove(item)
for i in range(N,10*N):
  if set(list(str(i))) <= set(Digit):
    print(i)
    exit()

Submission status: Accepted

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

nums = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
dd = d ^ nums

i = n
while True:
        if dd >= set(list(str(i))):
            print(i)
            exit()
        else:
            i += 1

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc042/tasks/arc058_a


def exist(target, array):
    for token in list(str(target)):
        if token in array:
            return True
    return False


n, _ = map(int, input().split())
d = input().split()

x = n
while True:
    if not exist(x, d):
        break
    x += 1

print(x)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
ans = N
while not set(str(ans)).isdisjoint(D):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, K: int, D: "List[int]"):

    D = set([str(c) for c in D])
    for ans in range(N, 10*N):
        if set(str(ans)).isdisjoint(D):
            print(ans)
            return

    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())
alg = set([0,1,2,3,4,5,6,7,8,9])
numeros = set(map(int, input().split()))

def contem(num, numeros):
	
	for l in str(num):
		if int(l) in numeros:
			return False
	return True
	

target = n


while not contem(target,numeros):
	target += 1

print(target)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = {x for x in input().split()}

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
s=set(input().split())
while 1:
  if set(list(str(n)))&s:n+=1
  else:break
print(n)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = tuple(map(int, input().split()))
flug = 1
while flug:
    flug = 0
    n2 = list(map(int,str(n)))
    for i in n2:
        if i in d:
            n += 1
            flug = 1
            break
print(n)

Submission status: Accepted

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

for i in range(1000000):
    if i < n:
        continue
    i1 = str(i)
    flag = True
    for j in range(len(i1)):
        if not flag:
            break
        i2 = int(i1[j])
        if i2 in d:
            flag = False
    if not flag:
        continue
    print(i)
    break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(str, input().split()))
possible = [str(i) for i in range(10) if str(i) not in d]
for i in range(n,10**5):
    for j in str(i):
        if j not in possible:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import itertools

n, k = map(int, input().split())
d = list(map(int, input().split()))
use = [i for i in range(10) if not i in d]

p = list(itertools.product(use, repeat=len(str(n))))

ans = float('inf')
for i in p:
    numlist = []
    if i[0] != 0:
        for g in range(len(str(n))):
            numlist.append(str(i[g]))
        num = int(''.join(numlist))
        if num>=n:
            ans=min(ans,num)

if ans==float('inf'):
    if min(use)==0:
        print(int(str(use[1])+"0"*len(str(n))))
    else:
        print(int(str(min(use))*(len(str(n))+1)))
else:
    print(ans)

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
D = sorted([int(i) for i in input().split()],reverse=True)

def is_ok(x):
  while x!=0:
    if x%10 in D:
      return False

    x //=10

  return True

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

Submission status: Accepted

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

def is_ok(x):
    while x != 0:
        if x % 10 in d:
            return False
        x //= 10
    return True

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

Submission status: Accepted

Solution code:
import functools

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

for i in range(n,n*11):
    count=0
    l = [int(x) for x in list(str(i))]
    for j in l:
        #print(j)
        if j  not in d :
            count+=1
    if count==len(l):
        print( int(functools.reduce(lambda x, y: x + y, [str(x) for x in l])))
        exit()

Submission status: Accepted

Solution code:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
D = list(map(str, input().split()))
D = set(D)
available = numbers - D

for i in range(N, 100000):
  nums = set(str(i))
  if nums <= available:
    print(i)
    break

Submission status: Accepted

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

price = N - 1

while True:
    flag = True
    price += 1
    price_str = str(price)
    for num in str(price_str):
        if int(num) in List:
            flag = False
            
    if flag == True:
        print(price)
        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, acos, atan, asin
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 STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

n, k = MAP()
d = set(S_LIST())
m = n
while True:
    if len(set(str(m)) & d) == 0:
        print(m)
        exit()
    m += 1

Submission status: Accepted

Solution code:
n,k = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]

for x in range(n, 100000):
    ans = 100000
    tmp = True
    for y in str(x):
        if int(y) in d:
            tmp = False
            break
    if tmp:
        ans = min(ans,x)
        break

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from operator import itemgetter
##stdin = open("sample.txt")

N, K = [int(x) for x in stdin.readline().rstrip().split()]
d = stdin.readline().rstrip()
D = d.replace(' ','')
D_list = [D[i] for i in range(0, len(D), 1)]
price = N
buy = False

while buy == False:
    price_str = str(price)
    price_list = [price_str[i] for i in range(0, len(price_str), 1)]
    price_kaburi = list(set(price_list)) 
    check = D_list + price_kaburi
    check_list = list(set(check))
    if len(check) == len(check_list):
        print(price)
        break
    else:
        price += 1

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(input().split())
D.insert(0,0)
n=0
while True:
    n+=1
    ok=True
    for i in list(str(n)):
        if i in D:
            ok=False
            break
    if ok and N<=n:
        print(n)
        break

Submission status: Accepted

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

while True:
    ok = True 
    for x in d:
        if x in str(n):
            ok = False
            break
    if ok:
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D=set(map(int,input().split()))
for i in range(n,10**5+10): 
  S=list(str(i))
  a=0
  for j in range(len(S)):
    if int(S[j]) in D:
      a=1
      break
  if a==0:
    print(i)
    break

Submission status: Accepted

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

while True:
    ok = True
    for x in d:
        if x in str(n):
            ok = False
            break
    if ok:
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
l = set(map(str, input().split()))
x = list(set(['0','1','2','3','4','5','6','7','8','9']) - l)
y = len(str(n))

from itertools import product
z = list(product(x, repeat = y))
z += list(product(x, repeat = y + 1))

for i in range(len(z)):
    z[i] = int(''.join(z[i]))

z.sort()
for j in z:
    if j >= n:
        print(j)
        break

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(str,input().split()))
ind_f = lambda x:x in D
for i in range(N,10*N):
  i_li = list(str(i))
  if  not any(map(ind_f, i_li)):
    print(i)
    break

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x

    

if __name__ == '__main__':
    N, K = mulinputs()
    *ds, = mulinputs()

    for n in range(N, 100000):
        nn = n
        is_ok = True
        while nn >= 1:
            num = nn % 10
            nn //= 10
            for dd in ds:
                if dd == num:
                    is_ok = False
                    break
            if not is_ok:
                break
        if is_ok:
            print(n)
            exit()

Submission status: Accepted

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

while True:
  l = set([s for s in str(num)])
  if l.isdisjoint(numbers):
    print(num)
    break
  num += 1

Submission status: Accepted

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

# antilist = list(set([0,1,2,3,4,5,6,7,8,9]) - (dlist))

res = []

digit = len(str(n))

while True:
    ok = True
    for i in range(0, len(str(n))):
        num = n // 10 ** (i) % 10
        if num in dlist:
            ok = False
    if ok:
        print(n)
        exit(0)
    n += 1

Submission status: Accepted

Solution code:
#042_C
n, k = map(int, input().split())
d = set(map(int, input().split()))
d_ = list({i for i in range(0, 10)} - d)
inf = 10 ** 7

def dfs(frm, cur):
    if frm == cur == 0:
        return inf
    if cur >= n:
        return cur
    
    x = 10 ** 7
    for k in d_:
        x = min(x, dfs(cur, cur * 10 + k))
        
    return x

print(dfs(-1, 0))

Submission status: Accepted

Solution code:
from collections import deque

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

nums = list("0123456789")
for d in D:
    nums.remove(d)


def dfs(N, nums):
    ans = 10 ** 9
    if "0" in nums:
        queue = deque(nums[1:])
    else:
        queue = deque(nums)

    while queue:
        tmp = queue.pop()
        if int(tmp) >= N:
            if int(tmp) < ans:
                ans = int(tmp)
        else:
            for n in nums:
                queue.append(tmp + n)

    return ans


print(dfs(N, nums))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,n*10+1):
  N=list(str(i))
  for j in range(len(N)):
    N[j]=int(N[j])
  N=set(N)
  d=set(d)
  if N.isdisjoint(d):
    print(i)
    exit()

Submission status: Accepted

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

able = []
for i in range(10):
    if i in Ds:continue
    able.append(i)
# print(able)

sN = str(N)
n = len(sN)
m = able[0] #最小


if int(sN[0]) > max(able):
    if m == 0:
        ans = str(able[1]) + str(able[0]) * n
    else:
        ans = str(able[0]) * (n+1)
    print(ans)
    exit()
prev = -1
flg = True #確定していない
ans = ""
for i,s in enumerate(sN):
    flg2 = False
    if flg:
        for j,a in enumerate(able):
            if int(s) < a:
                ans += str(a)
                flg = False
                flg2 = True
                break
            if int(s) == a:
                ans += str(a)
                flg = True
                flg2 = True
                break
        if not flg2:
            if prev == len(able)-1:
                if m == 0:
                    ans = str(able[1]) + str(able[0]) * n
                else:
                    ans = str(able[0]) * (n+1)
                print(ans)
                exit() 
            ans = ans[:-1]
            ans += str(able[prev+1]) + str(m)
            flg = False
    else:
        ans += str(m)    
    prev = j
    # print(ans)

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
d = set(map(str,input().split()))
OK = {str(i) for i in range(10)} - d


for i in range(N,100000):
  if set(str(i)) <= OK:
    print(i)
    exit()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

c = N

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

    flg = False

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

Submission status: Accepted

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

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

print(N)

Submission status: Accepted

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

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

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

if idx1 < len(nedan): #編集開始桁位置取得
    while idx1 >= 0:
        if tukaeru[-1] <= nedan[idx1]:
            idx1 = idx1 - 1
        else:
            break

    if idx1 == -1: #桁追加必要
        if tukaeru[0] == '0':
            nedan.insert(0, tukaeru[1])
        else:
            nedan.insert(0, tukaeru[0])
        idx1 = 1
    else: #桁追加不要
        for item1 in tukaeru:
            if item1 > nedan[idx1]:
                nedan[idx1] = item1
                break
        idx1 = idx1 + 1

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

print(''.join(nedan))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

D = num - D

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

Submission status: Accepted

Solution code:
from sys import stdin

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

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

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

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:
import sys

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

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

Submission status: Accepted

Solution code:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

rec_cal_pay(answer, 0, restrict)

Submission status: Accepted

Solution code:
#nが小さいので全部試せる
n,k = map(int,input().split( ))
d= set(input().split( ))
ans = n

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

use = [i for i in range(10)] #使える数字
for i in range(K): use.remove(D[i])

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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