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:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)
 
 
def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
            break
    return FirstBig
 
 
for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))
 
FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]
 
if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        if okLines[0] != '0':
            newMoney.insert(0, okLines[0])
        else:
            newMoney.insert(0, okLines[1])
        for i in range(ProblemFlag + 1, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Submission status: Accepted

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)


def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig


for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        if okLines[0] != '0':
            newMoney.insert(0, okLines[0])
        else:
            newMoney.insert(0, okLines[1])
        for i in range(ProblemFlag + 1, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Submission status: Accepted

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

while 1:
    digits = set(str(pay))
    digits = {int(d) for d in digits}
    if dislike.isdisjoint(digits): break
    else: pay += 1

print(pay)

Submission status: Accepted

Solution code:
a,b = map(int,input().split(" "))
ar = input().split(" ")
while True:
    count = 0
    for r in ar:
        if r in str(a):
            count += 1
            break
    if count == 0:
        print(a)
        break
    a += 1

Submission status: Accepted

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

for i in range(n,10*n):
  s =str(i)
  for c in s:
    if c in d:
      break
  else:
    print(i)
    exit()

Submission status: Accepted

Solution code:
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

for ans in range(int(N), 100000):
    flg = True
    for i in range(len(str(ans))):
        if str(ans)[i] in D:
          flg = False
          break

    if flg:
        print(ans)
        break

Submission status: Accepted

Solution code:
A,B = list(map(int,input().split()))
l_n = list(input().split())
sw = 0
for i in range(A,A*10+1):
    sw=0
    C = str(i)
    for j in C:
        if j in l_n:
            sw=1
            break
    if sw == 0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().strip().split())
diss = map(int, raw_input().strip().split())

like = [1] * 10
for d in diss: like[d] = 0

ok = 1
amt = n
for c in str(amt):
    if not like[int(c)]:
        ok = 0
        break

while not ok:
    amt += 1

    ok = 1
    for c in str(amt):
        if not like[int(c)]:
            ok = 0
            break

print amt

Submission status: Accepted

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

def check(n, d):
	# nがdに含まれているか
	# 含まれていないならばTrue
	s = str(n)
	for i in range(len(s)):
		if int(s[i]) in d:
			return False
	return True

res = n

while True:
	if check(res, d):
		print(res)
		break
	res += 1

Submission status: Accepted

Solution code:
N,K = input().split(' ')
line = input().split(' ')
for i in range(int(N),100000):
  m = True
  for j in range(len(str(i))):
    if str(i)[j] in line:
      m = False
      break
  if m == True:
    print(i)
    break

Submission status: Accepted

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

ans = N
for p in range(N, N+10**9):
    flag = True
    s = str(p)
    for c in s:
        if c in D:
            flag = False
            break

    if flag:
        break

print(s)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(input().split())
ans = 100000
for i in range(n, 100001):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        if ans > i:
            ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys

rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    D = set(map(int, rl().split()))
    
    for ans in range(N, 100000):
        str_ans = str(ans)
        flg = True
        for a in str_ans:
            if int(a) in D:
                flg = False
                break
        if flg:
            print(ans)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

for i in range(N, 10*N+1):
    s = str(i)
    for j in range(len(str(i))):
        if(s[j] in D):
            break
        if(j == len(str(i))-1):
            print(i)
            quit()

Submission status: Accepted

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

from itertools import count

for i in count(n):
    s = str(i)
    for bit in s:
        if bit in d:
            break
    else:
        print(i)
        break

Submission status: Accepted

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

for i in range(k,100000):
    for e in l:
        if e in str(i):
            break
    else:
        print(i)
        break

Submission status: Accepted

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

for i in range(k,100000):
    for e in li:
        if e in str(i):
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=[1]*10
for i in map(int,input().split()):
  D[i]=0
ans=''
while N>0:
  n=N%10
  N=N//10
  while D[n%10]==0:
    n+=1
  if n>9:
    N+=1
  elif N>0 and D[N%10]==0:
    for i in range(n):
      if D[i]==1:
        n=i
        break
  ans+=str(n%10)
if ans=='':
  print(N)
else:
  print(ans[::-1])

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = input().split()
ans = n-1
while True:
  ok = True
  ans += 1
  z = list(str(ans))
  for i in z:
    if i in d:
      ok = False
      break
  if ok:
    print(ans)
    break

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
X = set(input().split())
for i in range(N, 10**6):
    for c in str(i):
        if c in X:
            break
    else:
        break
print(i)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))

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

L = list(map(int,input().split()))
R = list(map(int,input().split()))

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

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''



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

use = [True]*10
for d in D:
    use[d] = False

for pay in range(N, N*1000):
    
    can = True
    pay_string = str(pay)
    for p in pay_string:
        if not use[int(p)]:
            can = False
            break

    if can:
        print(pay)
        sys.exit()

Submission status: Accepted

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


digits = [0]*10
digits_disliked = list(map(int, input().split()))

for i in digits_disliked:
    digits[i] = 1

for i in range(n, 10**7+1):
    temp = i
    flag = True

    while(temp):
        rem = temp%10
        temp = temp//10
        if(digits[rem] != 0):
            flag = False
            break
    
    if(flag == True):
        print(i)
        break

Submission status: Accepted

Solution code:
n,k = input().split(" ")
l = input().split(" ")
l1 = ['0','1','2','3','4','5','6','7','8','9']
d = sorted(list(set(l1)-set(l)))
i = int(n)
while(True):
    if set(list(str(i))).difference(set(d))==set():
        break
    else:
        i+=1
print(i)

Submission status: Accepted

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

for i in range(k,100000):
    for e in li:
        if e in str(i):
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = map(str, input().split())
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(n, 100000):
    Nums = set(str(i))
    if Nums <= left:
        print(i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(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


MOD = int(1e09) + 7

def main():
    N,K = cin.mapInt()
    D = set(cin.string().split())
    while True:
        if len(D & set(str(N))) == 0:
            break
        N +=1
    print(N)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

flag = False

inf = 10 ** 6

while flag == False:
  for i in range(N,inf):
    L = str(i)
    for j in L:
      if int(j) in D:
        break
    else:
      print(i)
      flag = True
      break

Submission status: Accepted

Solution code:
s, k = [int(i) for i in input().split(" ")]
num = [int(i) for i in input().split(" ")]

def check(n):
	for _s in str(n):
		if int(_s) in num:
			return True
	return False

while check(s):
	s += 1
	
print(s)

Submission status: Accepted

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

checker = list(map(str, input().split()))

cont = True
while cont:
    keep = True
    for nn in str(n):
        if nn in checker:
            keep = False
            break
        
    if keep: break
    n += 1

print(n)

Submission status: Accepted

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

ans = 0
for i in range(N, 10**6):
    t = list(str(i))
    f = 0
    for s in t:
        if int(s) in D:
            break
        f += 1
    if f == len(t):
        print(i)
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
*D, = map(int, input().split())
D = set(D)
L = {1,2,3,4,5,6,7,8,9,0} - D
for i in range(N, N*10):
    tmp = i
    num = set()
    while i > 0:
        num.add(i%10)
        i = i // 10
    if num.isdisjoint(D):
        print(tmp)
        exit()

Submission status: Accepted

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

for i in range(N,100000):
    for d in D:
        if d in list(str(i)):
            break
    else:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dlst = [int(i) for i in input().split()]
lst = []
for i in range(10):
  if i not in dlst:
    lst.append(str(i))
for i in range(n, 10 * n + 1):
  a = True
  for j in str(i):
    if j not in lst:
      a = False
      break
  if a:
    print(i)
    quit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = [a for a in input().split()]

def chk(i):
    s = str(i)
    for a in s:
        if a in A:
            return 0
    return 1

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

Submission status: Accepted

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

a_L = [str(val) for val in range(10)]

use_num = list(set(a_L) - set(d_L))

ans = 0
while True:
    c = list(set(list(str(n)))) + use_num
    if len(use_num) == len(list(set(c))):
        print(n)
        exit()

    n += 1

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    d = ''.join(input().split())
    ans=str(n)
    while True:
        key=0
        for c in d:
            if c in ans:
                key=1
                ans=str(int(ans)+1)
        if key==0:
            print(ans)
            return   

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def des(n,D):
    if n%10 in D:
        return False
    elif n>=10 and (n//10)%10 in D:
        return False
    elif n>=100 and (n//100)%10 in D:
        return False
    elif n>=1000 and (n//1000)%10 in D:
        return False
    elif n>=10000 and n//10000 in D:
        return False
    return True

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

while not des(N,D):
    N+=1
print(N)

Submission status: Accepted

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

for i in range(n, n*11):
  for d in Ds:
    if d in list(map(int, list(str(i)))):
      break
  else:
    print(i)
    exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [str(i) for i in range(10) if i not in a]
anslist = b + list(itertools.product(b,b))
anslist += list(itertools.product(b,b,b))
anslist += list(itertools.product(b,b,b,b))
anslist += list(itertools.product(b,b,b,b,b))
anslist += list(itertools.product(b,b,b,b,b,b))
anslist = [int("".join(i)) for i in anslist ]
#print(anslist)
#print(b)
anslist.sort()
for i in anslist:
    if i >= n:
        print(i)
        exit()

Submission status: Accepted

Solution code:
# ABC042C - こだわり者いろはちゃん / Iroha's Obsession (ARC058)
def main():
    N, K, *D = map(int, open(0).read().split())
    D = set(D)
    while any(int(i) in D for i in str(N)):
        N += 1
    print(N)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

def isntD(n):
    c = 0
    for i in range(len(str(n))):
        if D.count(int(str(n)[i])) == 1:
            c += 1
    return c
    

while N < 100000:
    if isntD(N) == 0:
        print(N)
        break
    N += 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
U = []
for i in range(10):
    if not i in D:
        U.append(i)
ans = float("inf")
import itertools

for i in range(6):
    for v in itertools.product(U,repeat=i):
        tmp = ""
        for s in v:
            tmp += str(s)
        if tmp != "":
            tmp = int(tmp)
            if tmp>=N and tmp<ans:
                ans = tmp
print(ans)

Submission status: Accepted

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

ans = N
while any([i in D for i in str(ans)]):
    ans += 1

print(ans)

Submission status: Accepted

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

while True:
  S = str(M)
  flag = 0
  for s in S:
    if int(s) in D:
      M += 1
      break
  else:
    break
print(S)
#N = str(N)
#L = len(N)
#for i in range(L):
#  j = -1-i
#  x = int(N[j])
#  if int(N[j]) in D:
#    while int(N[j]) in D:

Submission status: Accepted

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

safe = set([str(i) for i in range(10) if not str(i) in D])

ans = N
while not all([i in safe for i in str(ans)]):
    ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = {str(i): 0 for i in list(map(int, input().rstrip('\n').split()))}

    for i in range(n, 10 ** 15):
        t = str(i)
        b = True
        for j in range(len(t)):
            if t[j] in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

answer = n

while not all(w not in li_d for w in str(answer)):
    answer += 1

print(answer)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(input().split())
for i in range(n, 10**6):
  if all([j not in a for j in str(i)]):
 #   print([j for j in str(i)])
    print(i)
    exit()

Submission status: Accepted

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

while True:
    S = str(N)
    hit = True
    for s in S:
        if s in D:
            N += 1
            hit = False
            break
    if hit:
        print(N)
        exit()

Submission status: Accepted

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

for i in range(100000):
    if set(str(i)).isdisjoint(d) and i >= n:
        print(i)
        exit()

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = list(map(int, input().rstrip('\n').split()))
    for i in range(n, 10 ** 10):
        t = list(str(i))
        b = True
        for j in range(len(t)):
            if int(t[j]) in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import itertools
n, k = map(int, input().split())
d = list(map(int, input().split()))
u = []
for i in range(0, 10):
    if i not in d:
        u.append(i)
for j in range(1, 6):
    for i in itertools.product(u, repeat=j):
        t = int("".join(map(str, i)))
        if n <= t <= 100000:
            print(t)
            exit()

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl
N, K = map(list, input().split())
D = list(map(int, input().split()))
D = [i for i in range(10) if not i in D]
res = []
big = 0
if int("".join([str(D[-1])] * len(N))) < int("".join(N)):
  if int(K[0]) < 9:
    if D[0] == 0:
      res = [D[1]] + [0] * len(N)
    else:
      res = [D[0]] * (len(N) + 1)
  else:
    res = [D[0]] * (len(N) + 1)
else:
  for i in range(len(N)):
    if big == 0:
      res.append(D[bl(D, int(N[i]))])
    else: res.append(D[0])
    if res[i] > int(N[i]): big = 1
print("".join(list(map(str, res))))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = tuple(map(str, input().split()))
for i in range(n, 10 ** 9):
    b = True
    for s in tuple(str(i)):
        if s in d:
            b = False
            break
    if b:
        print(i)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
d = [int(i) for i in readline().split()]

ng = [1 if i in d else 0 for i in range(10)]


for i in range(n,10**6):
    s = str(i)
    for j in s:
        if ng[int(j)]: break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC58C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
k=hoge[1]

d=[]
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,k):
	d.append(hoge[i])

payment=0
for i in range(0,100000):
	payment=n+i
	for j in range(0,k):
		if(str(d[j]) in str(payment)):
			break
		if(j==k-1):
			print(payment)
			sys.exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
U = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
for d in list(map(int,input().split())):
    if d in U:
        U.remove(d)

def check(n):
    for s in str(n):
        if int(s) not in U:
            return False
    if n >= N:
        return True
    else:
        return False

ans = N
while not check(ans):
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(list(map(int, input().split())))
d = list(set([i for i in range(10)])-d)
d.sort()
import itertools

import sys
for k in range(6):
  for i in itertools.product(d, repeat=k):
    ans = 0
    for j in range(len(i)):
      ans += i[-j-1]*10**j
    if ans >= n:
      print(ans)
      sys.exit()

Submission status: Accepted

Solution code:
import itertools
n,k=map(int,input().split())
l=list(range(10))
l_tmp=list(map(int,input().split()))
for i in l_tmp:
    l.remove(i)
keta=len(str(n))
li=list(itertools.product(l,repeat=keta))
ans=[int("".join(map(str,i))) for i in li]
tmp=[str(min([i for i in l if i>0]))]+[str(min(l))]*keta
ans.append(int("".join(tmp)))
print(min([i for i in ans if i>=n]))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
a=set(map(str,input().split()))
for i in range(N,10**5):
    if a&set(str(i))==set():
        print(i)
        break

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, K = input().split()
int_N = int(N)
arr = list(input().split())
max_num = pow(10,6)

for i in range(int_N, max_num):
    li = list(set(list(str(i))))
    for j in range(len(li)):
        if li[j] in arr:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
# ARC058C - こだわり者いろはちゃん / Iroha's Obsession (ABC042C)
def main():
    n, k = list(map(int, input().rstrip().split()))
    D = set(map(int, input().rstrip().split()))
    ans = n
    while any(int(i) in D for i in str(ans)):
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k,*d=map(int,open(0).read().split())
t=set(map(str,set(d)))
#print(t)
for i in range(n,1000000):
    if set(str(i))&t:
        continue
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, M = mi()
nos = set(input().split())
#昇順ソート
availables = sorted(list(set(map(str, (0,1,2,3,4,5,6,7,8,9))) - nos))

#方針
#桁数が変われば、(1)0が使える場合は、使える一番低い数字+あとは全部0
#              (2)0が使えない場合は、使える一番低い数字で埋めるだけ
#とはいえ、元々が3桁とかなら全探索で十分
#5桁になると怪しいので、(1)(2)を活かす

#まずは9999までの間に答えがあるかどうか
#N=9999でも、9が嫌いじゃない場合があるから探索する
ans = 0
for i in range(N, 100000):
  if not (set(str(i)) & nos): #使えない(nos)のに使ってる(set内)が無かったら
    ans = i
    break


print(ans)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, M = mi()
nos = set(input().split())
#昇順ソート
availables = sorted(list(set(map(str, (0,1,2,3,4,5,6,7,8,9))) - nos))

#方針
#桁数が変われば、(1)0が使える場合は、使える一番低い数字+あとは全部0
#              (2)0が使えない場合は、使える一番低い数字で埋めるだけ
#とはいえ、元々が3桁とかなら全探索で十分
#5桁になると怪しいので、(1)(2)を活かす

#まずは9999までの間に答えがあるかどうか
#N=9999でも、9が嫌いじゃない場合があるから探索する
ans = 0
for i in range(N, 10000):
  if not (set(str(i)) & nos): #使えない(nos)のに使ってる(set内)が無かったら
    ans = i
    break
if ans == 0:
  #もしここまでで答えが出ていなかったら
  if '0' in availables:
    print(str(list(availables)[1])+str(list(availables)[0])*4)
    exit()
  else:
    print(str(list(availables)[0])*5)
    exit()

print(ans)

Submission status: Accepted

Solution code:
p=input().rstrip().split(' ')
q=input().rstrip().split(' ')
for i in range(int(p[0]),1000000000000):
    t=list(str(i))
    G=0;
    for j in range(0,len(t)):
        if t[j] not in q:
            continue;
        else:
            G=1;
            break;
    if G==0:
        print(i)
        break;

Submission status: Accepted

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

start = N
while True :
    start_list = list(str(start))
    flag = True
    for i in start_list:
        if i in hate_num :
            flag = False
    if flag :
        print(start)
        break
    else :
        start += 1

Submission status: Accepted

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

    numbers = [str(number) for number in range(n, 10 * n)]
    for number in numbers:
        if ok(number, D):
            print(number)
            break


def ok(number, D):
    return len({c for c in number} & D) == 0


main()