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 = input().split()
for n in range(N, 100000):
	if all(d not in str(n) for d in D):
		print(n)
		exit()

Submission status: Accepted

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

search = True
while search:
    for i in str(N):
        if not i in D:
            search = False
            continue
        N += 1
        search = True
        break

print(N)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N, K = s_inpl()
D = inpl()

l = set(range(0, 10))  - set(D)
c = copy.deepcopy(N)
while True:
    ls = set([int(i) for i in list(str(c))])
    if ls.issubset(l):
        print(c)
        break
    c += 1

Submission status: Accepted

Solution code:
# coding: UTF-8


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

dislike_nums = input().split()

def contains_dislike_number(num):
    for n in dislike_nums:
        if n in str(i):
            return True
    return False

for i in range(N, 10*N+1):
    if not contains_dislike_number(i):
        print(i)
        break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = set(input())
while len(set(str(n))&d):
	n += 1
print(n)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
D = list(input().split())
while True:
	if any (d in str(n) for d in D):
		n += 1
	else:
		print(n)
		exit()

Submission status: Accepted

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

# input
N, K = map(int, input().split())
D = input().split()
# getans
def is_in_d(s):
	for d in D:
		if d in s:
			return True
	return False
for i in range(100000):
	ans = str(N+i)
	if not is_in_d(ans):
		break
# output
print(ans)

Submission status: Accepted

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

X = list(map(int, input().split()))

def detecter(n):
    A = list(str(n))
    for i in A:
        if(int(i) in X):
            return False
    return True

while(not(detecter(n))):
    n += 1
print(n)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
for i in range(N,100000):
	Ai=str(i)
	if all((str(j) not in Ai)for j in D):
			print(i)
			break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
D = set([int(d) for d in input().split()])
num = set([0,1,2,3,4,5,6,7,8,9])
D = list(num - D)
D.sort(reverse=True)
_ = 10**7
def abcC(x, ans):
    if len(x) == len(str(n))+3:
        return ans
    if n <= int(x) < ans:
        ans = int(x)
    elif n > int(x):
        for i in D:
            ans = abcC(x+str(i),ans)
    return ans
        
print(abcC('0',_))

Submission status: Accepted

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

while 1:
    temp = list(str(n))
    for c in d:
        #print(c, temp)
        if c in temp:
            #print('a')
            break
    else:
        print(n)
        exit()
    n += 1
    continue

Submission status: Accepted

Solution code:
#ABC042C
N,K=map(int,input().split())
D=list(map(int,input().split()))
E=[0]*10
for d in D:
    E[d]=1

while(1):
    for n in str(N):
        if E[int(n)]==1:
            N+=1
            break
    else:
        break

print(N)

Submission status: Accepted

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

def valid(x):
    while x:
        if (x % 10) in list:
            return 0
        x //= 10
    return 1

cur = n
while True:
    if valid(cur):
        break
    cur += 1

print(cur)

Submission status: Accepted

Solution code:
n,k=input().split()
n=int(n)
k = int(k)
bl=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
L = [int(x) for x in input().split()]
for i in L:
   x = int(i)
   bl[x]=1
while True:
     s = str(n)
     flag=0
     for i in s:
         if bl[int(i)]==1:
             n = n + 1
             flag = 1
             break
     if flag == 0:
         break
print(n)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
s = input().split()
t = 1
for i in range(10 * n):
    n2 = list(str(n))
    for j in range(len(n2)):
        if s.count(n2[j]) == 1:
            n = n + 1
            t = 0
            break
    if t == 1:
        break
    else:
        t = 1
    
print(n)

Submission status: Accepted

Solution code:
n=int(input().split()[0]);a=set(input())
while a&set(str(n)):n+=1
print(n)

Submission status: Accepted

Solution code:
import sys
N, K = map(int, input().split())
D = list(input().split())
D = set(D)
for i in range(N, 100 * N):
    if D & set(str(i)):
        continue
    else:
        print(i)
        sys.exit()

Submission status: Accepted

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

#print(D)
#print(list(str(N)))

while 1:
    check = True
    for i in D:
        if i in list(str(N)):
            check = False
            break
    if check:
        break
    
    N += 1

print(N)

Submission status: Accepted

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

while len(d&set(str(n)))!=0:
    n+=1
print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
a=[]
for i in range(10):
    sum=0
    for x in d:
        if x==i:
            break
        else:
            sum+=1
    if sum==k:
        a.append(i)
a=set(a)
for i in range(n,10*n+1):
    b=[]
    x=len(str(i))
    y=str(i)
    for j in range(x):
        b.append(int(y[j]))
    b=set(b)
    if a>=b:
        print(i)
        break

Submission status: Accepted

Solution code:
l=[str(x) for x in range(100000)]
n,k=map(int,input().split())
l2=list(map(str,input().split()))
ind=l.index(str(n))
while True:
  a=l[ind]
  f=False
  for x in l2:
    if x in a:
      f=True
  if not f:
    break
  ind+=1
print(a)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
x = [ int(i) for i in input().split() ]
a = [ 0 for i in range(10) ]
for i in x:
    a[i] = 1

def check(n):
    s = str(n)
    for i in s:
        if a[int(i)] == 1:
            return False
    return True

while check(n) == False:
    n += 1

print(n)

Submission status: Accepted

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


while True:
  flag = True
  for i in range(len(str(n))):
    if str(n)[i] in d:
      flag = False
  if flag:
    print(n)
    exit()
  n = n+1

Submission status: Accepted

Solution code:
import sys
N,K = [int(n) for n in input().split()]
D = set([str(n) for n in input().split()])
# OK = sorted(list(set([0,1,2,3,4,5,6,7,8,9]) - D))
for i in range(N,100001):
    stri = set(list(str(i)))
    find = True
    for d in D:
        if d in stri:
            find = False
            break
    if find:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = set([int(i) for i in input().split()])
num = set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) - A

for i in range(n, n * 10 + 1):
    for j in list(str(i)):
        if int(j) not in num:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
price, n = [int(i) for i in input().split(' ')]
exclude_nums = [int(i) for i in input().split(' ')]

nums = set([i for i in range(0,10)])

for num in exclude_nums:
    nums.discard(num)

while True:
    safe = True
    for num in str(price):
        if int(num) in nums:
            pass
        else:
            price += 1
            safe = False
            break
    if safe:
        print(price)
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]
d=[i for i in input().split()]
num=[i for i in range(1,10) if (i in d)==False]
def check(number):
    s=str(number)
    result=True
    for i in range(len(s)):
        if s[i] in d:
            result=False
    return result
if check(n):
    print(n)
else:
    while True:
        if check(n+num[0]):
            print(n+num[0])
            break
        else:
            n+=num[0]

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007


#A
def check(n):
    n = list(map(int,list(str(n))))
    s = 0
    for i in n:
        s += f[i]
    return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
    f[i] = 1
while 1:
    if check(n):
        print(n)
        quit()
    n += 1
#B

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

CANUSE = [x for x in filter(lambda x: not x in D, range(0,10))]


candidates = []
q = [("")]
# print(CANUSE)

while q:
    s = q.pop()
    if len(s) >= 6:
        continue
    if ( int(s) if s != "" else 0 )  >= N:
        candidates.append(int(s))
        continue

    for ch in CANUSE:
        q.append( s+str(ch) ) 

print(min(candidates))

Submission status: Accepted

Solution code:
def validate(n, d: set) -> bool:
    while n > 0:
        # print(n)
        r = n%10
        if r in d:
            return False
        n //= 10
    return True


def solve(n, d):
    d = set(d)
    for i in range(n, 10**6):
        if validate(i, d):
            return i
    return -1


def main():
    n, k = map(int, input().split())
    d = [int(x) for x in input().split()]
    print(solve(n, d))


if __name__ == '__main__':
    assert validate(2000, [1,3,4,5,6,7,8,9])
    assert not validate(1002, [1,3,4,5,6,7,8,9])
    main()

Submission status: Accepted

Solution code:
N, _ = map(int, input().split())
D = list(map(int, input().split()))
E = [str(i) for i in [0,1,2,3,4,5,6,7,8,9] if i not in D]
E
while not all(n in E for n in str(N)):
    N+=1
print(N)

Submission status: Accepted

Solution code:
BASE, N = map(int, input().split())
NGs = input().split()

def solve():
    def is_valid(num):
        s_num = str(num)
        for ng in NGs:
            if s_num.count(ng):
                return False
        return True

    # print(BASE, N)
    # print(NGs)

    num = BASE

    while not is_valid(num):
        num += 1

    return num

res = solve()
print(res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
x=0
p=n
while x==0:
    q=list(str(p))
    x=1
    for y in q:
        if  y in d:
            p+=1
            x=0
            break
print(p)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
M = N
while 1:
    flag = False
    for x in str(M):
        if int(x) in D:
            flag = True
            break
    if flag == True:
        M += 1
    else:
        print(M)
        break;

Submission status: Accepted

Solution code:
import itertools

N, M = map(int, input().split())
L = list(map(str, input().split()))
tmp = [0 for _ in range(10)]
seq = []

for i in range(10 ** 5):
    tmp = str(i)
    flag = True
    for j in range(len(tmp)):
        if tmp[j] in L:
            flag = False
        
    if i >= N and flag == True:
        res = i
        break

        
print(res)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(input())
b = any(i in str(n) for i in d)
while b == 1:
    n += 1
    b = any(i in str(n) for i in d)
print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D=list(map(int,input().split()))
nums=[i for i in range(10) if i not in D]

def str_check(string):
  string=str(string)
  for i in string:
    if int(i) not in nums:
      return False
  return True

for i in range(1,100000):
  if str_check(i)==True and n<=i:
    print(i)
    exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    like_numbers = [i for i in range(10) if i not in d]
    digit_count = len(list(map(str, list(str(n)))))
    digit = [0] * digit_count
    ans = list()

    def dfs(count):
        if count == digit_count:
            return ans.append(int(''.join(map(str, digit))))

        for like_number in like_numbers:
            digit[count] = like_number
            dfs(count + 1)

    dfs(0)

    if max(ans) >= n:
        print(min([a for a in ans if a >= n]))
    else:
        digit_count += 1
        digit = [0] * digit_count
        dfs(0)
        print(min([a for a in ans if a >= n]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

def main():
    n, _ = map(int, input().split())
    d = [int(s) for s in input().split()]
    p = [i not in d for i in range(10)]

    print(solve(n, p))

def solve(n, p):
    def check(i):
        if i == 0:
            return True
        if not p[i % 10]:
            return False
        return check(i // 10)

    for i in itertools.count(n):
        if check(i):
            return i

main()

Submission status: Accepted

Solution code:
#coding:utf-8
# O(Dlogn)解法?
N,K=map(int, raw_input().split(" "))   
D=map(int, raw_input().split(" "))   
keta=len(str(N))
strN=str(N)
ans1=""
for x in range(keta-1):
    p=int(strN[keta-x-1])
    d=0
    for dd in range(10):
        if dd not in D:
            d=dd
            break
    ans1=str(d)+ans1
candidate=int(strN[0])
def ok(n):
    s=str(n)
    for ss in s:
        if int(ss) in D: return False
    return True
while True:
    if ok(candidate) and int(str(candidate)+ans1)>=N: # shit
        break
    candidate+=1

ans1=str(candidate)+ans1
if ok(N):
    print(N)
else:
    print(int(ans1))

Submission status: Accepted

Solution code:
def contains_digit(n: int, d: set):
    flag = False
    while n > 0:
        flag = flag or (n % 10 in d)
        n //= 10
    return flag

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

for i in range(N, N*10):
    if not contains_digit(i, D):
        print(i)
        break

Submission status: Accepted

Solution code:
price, num = input().split(" ")
dislike = input().split(" ")
for i in range(int(price), 100000):
    if set(dislike) & set(str(i)):
        continue
    else:
        print(i)
        break

Submission status: Accepted

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

for i in range(n, 100000):
  if bool(set([int(x) for x in str(n)]) & d_set ) is False:
    print(n)
    break
  n += 1

Submission status: Accepted

Solution code:
n=input()[:-2]
s=sorted(set(range(10))-set(map(int,input().split())))
s=[str(i)for i in s]
if all(i in s for i in n):
  print(n)
  exit()
f=0
t=''
for i in n:
  if f:
    t+=s[0]
  elif i in s:
    t+=i
  else:
    for j in s:
      if int(j)>int(i):
        t+=str(j)
        f=1
        break
    else:
      break
else:
  print(t)
  exit()
t=(s[0]*(s[0]!='0')or s[1])+s[0]*len(n)
print(t)

Submission status: Accepted

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

i = N
while True:
    flg = True
    for j in str(i):
        if int(j) in D:
            flg = False
            break

    if flg == True:
        print(i)
        exit()

    i += 1

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
for j in range(N,N*10):
    if N <= j:
        L = {int(result) for result in str(j)}
        if D.isdisjoint(L):
            D_love = j
            break    
print(D_love)

Submission status: Accepted

Solution code:
N,K =map(int,input().split())
D =[i for i in input().split()]
s =True
while True:
  Ns =str(N)
  for i in D:
    if i in Ns:
      s =False
  if not s:
    s =True
    N += 1
  else:
    break
print(N)

Submission status: Accepted

Solution code:
D, K = map(int, input().split())
S = set(input().split())
while any((c in S) for c in str(D)):
    D += 1
print(D)

Submission status: Accepted

Solution code:
def foo(D, S):
    while any((c in S) for c in str(D)):
        D += 1
    return D

D, K = map(int, input().split())
S = set(map(str, input().split()))
print(foo(D, S))

Submission status: Accepted

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

for i in range(n * 10):
    for j in str(n + i):
        if j in A:
            break
    else:
        print(n + i)
        break

Submission status: Accepted

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

def isok(yen, D):
    flag = True
    for y in yen:
        if y in D:
            flag = False
            break
    return flag

while True:
    if isok(str(N), D):
        print(N)
        break
    N += 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = list(input().split())
for i in range(10 * n):
    for a in A:
        if a in str(n + i):
            break
    else:
        ans = n + i
        break
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Hate = list(map(int, input().split()))
D = [d for d in range(10) if d not in Hate]
D0 = D[:]
if 0 not in D:
    D0.insert(0, 0)
for d4 in D0:
    for d3 in D0:
        for d2 in D0:
            for d1 in D0:
                for d0 in D:
                    M = 10000 * d4 + 1000 * d3 + 100 * d2 + 10 * d1 + d0
                    if N <= M:
                        if 0 == D[0] or M <= 99:
                            print(M)
                            break
                        elif M <= 999 and d1 != 0:
                            print(M)
                            break
                        elif 1000 <= M <= 9999 and d1 != 0 and d2 != 0:
                            print(M)
                            break
                        elif 10000 <= M and d1 != 0 and d2 != 0 and d3 != 0:
                            print(M)
                            break
                else:
                    continue
                break
            else:
                continue
            break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
de_num = list(map(int, input().split()))
ok_num = []
cand_num = []
ans_num = []
#print(de_num)

for i in range(10):
  if i not in de_num:
    ok_num.append(i)
#print(ok_num)

for i in ok_num:
  for j in ok_num:
    for k in ok_num:
      for l in ok_num:
        for m in ok_num:
          if len(str(N)) == 4:
            num = 10000*i + 1000*j + 100*k + 10*l + m
            cand_num.append(num)
            num_s = 1000*j + 100*k + 10* l +m
            cand_num.append(num_s)
          elif len(str(N)) == 3:
            num = 1000*j + 100*k + 10*l + m
            cand_num.append(num)
            num_s = 100*k + 10*l + m
            cand_num.append(num_s)
          elif len(str(N)) == 2:
            num = 100*k + 10*l + m
            cand_num.append(num)
            num_s = 10*l + m
            cand_num.append(num_s)
          elif len(str(N)) == 1:
            num = 10*l + m
            cand_num.append(num)
            num_s = m
            cand_num.append(num_s)
            

for cd in cand_num:
  if cd >= N:
    ans_num.append(cd)

print(min(ans_num))

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())

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

for i in range(10*n):
  judge = n+i
  if ketajudge(judge) == True:
    print(judge)
    break

Submission status: Accepted

Solution code:
from itertools import product as p
n,k=map(int,input().split())
*d,=map(int,input().split())

cd={i for i in range(10)}-set(d)

*a,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=1)]))
*b,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=2)]))
*c,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=3)]))
*d,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=4)]))
*e,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=5)]))

print((a+b+c+d+e)[0])

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=set(input())
while sum(i in D for i in str(N))>0:
    N+=1
print(N)

Submission status: Accepted

Solution code:
def dfs(x):
    if x > N * 10:
        return
    if x >= N:
        cand.append(x)
    for y in not_dislike:
        dfs(x*10 + y)

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

not_dislike = set(range(10)) - D
cand = []
for x in not_dislike-set([0]):
    dfs(x)
print(min(cand, key=lambda x: abs(x-N)))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N, N*10):
    for j in map(str, D):
        if j in list(str(i)):
            break
    else:
        print(i)
        exit()

Submission status: Accepted

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

for i in range(N, N*10):
    for j in D:
        if j in list(str(i)):
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n=int(input().split()[0])
d=input().split()
while True:
    v=True
    for i in str(n):
        if i in d:
            v=False
            break
    if v:
        print(n)
        break
    n+=1

Submission status: Accepted

Solution code:
price, amount = map(int, input().split())
hate_set = set(input().split())

while True:
    price_set = set([ a for a in str(price)])
    
    if hate_set & price_set == set():
        break
    else:
        price += 1

print(price)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
hate = input().split()
def check(number,hate):
    for i in range(K):
        if str(number).count(hate[i])!=0:return False
    return True
number=N
while not check(number,hate):
    number+=1
print(number)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N,100000):
    flag = 0
    for x in str(i):
        if int(x) in L:
            flag = 1
    if flag == 0:
        print(i)
        exit()

Submission status: Accepted

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

flag = True
while flag:
    flag = False
    tmp = str(N)
    for d in D:
        if d in tmp:
            N += 1
            flag = True
            break

print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
dislike = [i for i in input().split()]
for num in range(N,10**6):
    ok = True
    for s in str(num):
        if s in dislike:
            ok = False
    if ok :
        print(num)
        break
    else:
        continue

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = input().split()
d = [int(m) for m in a]
aset = set(a)
i = n
while True:
    k = list(str(i))
    klen = len(k)
    for j in range(klen):
        if k[j] in aset:
            i += 10 ** (klen - j - 1)
            i -= i % (10 ** (klen - j - 1))
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().strip().split())
setD = set(input().strip().split())
for i in range(N, 100000):
  if not setD.intersection(set([c for c in str(i)])):
    print(i)
    break

Submission status: Accepted

Solution code:
n,k=input().split()
n=int(n)
k=int(k)
d=input().split()
d=list(map(int,d))
a=[0]*10
flag=True
for i in d:
    a[i]+=1
while 1:
    flag=True
    tmp=n
    while tmp!=0:
        if(a[tmp%10]!=0):
            flag=False
            n+=1
            break
        tmp//=10
    if flag==True:
        print(n)
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(N,100000):
    # 禁止文字との共通集合がなければ良い
    if not D & set(str(i)):
        break

print(i)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
like = list(map(str, set(range(10)) - set(map(int, input().split()))))

while True:
  count = 0
  for c in str(n):
    if c in like:
      count += 1
      
  if count == len(str(n)):
    print(n)
    break
  
  n += 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = input().split()
for r in range(n, n*10):
    s = "{}".format(r)
    for x in d:
        if x in s:
            break
#for else構文 for 文が全て終わった時に実行される
    else:
        print(r)
        break

Submission status: Accepted

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

a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(d)

a = sorted(list(a))
l = len(str(n))
c = ""
for i in range(l):
    c += str(a[-1])

if int(c) < n:
        if a[0] == 0:
            ans = str(a[1])
        else:
            ans = str(a[0])
        for i in range(l):
            ans += str(a[0])
        ans = int(ans)
else:
    ans = 10000
    for v in product(a, repeat=l):
        tmp = ""
        for i in v:
            tmp += str(i)
        if int(tmp) >= n:
            ans = min(ans, int(tmp))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
d=list(map(int,(input().split())))
ans = 0
for i in range(N,100000):
    temp = str(i)
    n_len = len(temp)
    for j in range(n_len):
        if int(temp[j]) in d:
            break
        elif j == n_len-1:
            ans = 1
            break
    if ans == 1:
        print(temp)
        break

Submission status: Accepted

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

for R in range(N, N * 10):
    S = '{}'.format(R)
    for d in D:
        if d in S:
            break
    else:
        print(R)
        break

Submission status: Accepted

Solution code:
def fukumu(D, kazu):
    for i in str(kazu):
        if D.count(i) == 0:
            continue
        else:
            return True
    return False

def keisan(N, D):
    kazu = N
    while fukumu(D, kazu):
        kazu += 1
    return kazu

N, K = [int(i) for i in input().split()]
D = input().split()
print(keisan(N,D))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
B = list(map(int,input().split()))
A = [i for i in range(0,10)]
for number in B:
    A.remove(number)

for i in range(n,10*n+1):
    for j in str(i):
        if not int(j) in A:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
l=[0,1,2,3,4,5,6,7,8,9]
for i in range(k):
  l.remove(d[i])
L=[]
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        for j5 in range(len(l)):
          L.append(l[j1]*10000+l[j2]*1000+l[j3]*100+l[j4]*10+l[j5])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        L.append(l[j1]*1000+l[j2]*100+l[j3]*10+l[j4])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      L.append(l[j1]*100+l[j2]*10+l[j3])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    L.append(l[j1]*10+l[j2])
for j1 in range(len(l)):
  L.append(l[j1])
L.sort()
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
ok = [i for i in range(10) if i not in d]
ans = []

def solve(pay):
	if pay == "00000":
		return
	if pay != "" and int(pay) >= n:
		ans.append(pay)
		return
	for c in ok:
		solve(pay + str(c))
	return

solve("")
print(min(list(map(int, ans))))

Submission status: Accepted

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

U=[i for i in range(10) if i not in D]

Keta=1
while True:
    if N>U[-1]*(sum(10**(i) for i in range(Keta))):
        Keta+=1
    else:
        break

N_copy=N

Result=[]
for k in range(Keta):

    for u in U:
        if u*(10**(Keta-k-1))+U[-1]*(sum(10**(i) for i in range(Keta-k-1)))>=N_copy:
            Result.append(u)
            N_copy-=u*(10**(Keta-k-1))
            break
#    print u
#    print N_copy
#    print Keta
    if N_copy<=0:
        while len(Result)<Keta:
            Result.append(U[0])
        break

Ans=sum(Result[i]*(10**(Keta-i-1)) for i in range(len(Result)))
print Ans

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
while True:
    s = str(n)
    poss = False
    for i in s:
        if int(i) in a:
            poss = True
            break
    if not poss:
        print(n)
        exit(0)
    n += 1