Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



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


Sample output:
2000

Submission status: Accepted

Solution code:
import sys
line = []
for i in sys.stdin.readlines():
    line.append(i.rstrip())
data = line.pop(0).split(" ")
num_list = line.pop().split(" ")

def pick_up(num_list):
    use_list = ['0','1','2','3','4','5','6','7','8','9']
    for i in num_list:
        use_list.remove(i)
    return use_list

def advance(n_list, num):
    n_list[len(n_list)-1] += 1
    while((num) in n_list):
        chk = n_list.index(num)
        if chk == 0:
            return [0 for i in range(len(n_list))]
        else:
            n_list[chk] = 0
            n_list[chk-1] += 1
    return n_list

def solve(num, num_list):
    use_list = pick_up(num_list)
    ans_list = [0 for i in range(len(num))]
    count = 0

    while(count < len(use_list)**len(ans_list)):
        ans_num = ""
        for i in ans_list:
            ans_num += use_list[i]
        if (int(ans_num) - int(num) >= 0):
            break
        ans_list = advance(ans_list, len(use_list))
        count += 1

    if count == len(use_list)**len(ans_list):
        ans_num = ""
        if use_list[0] != "0":
            for i in range(len(num)+1):
                ans_num += use_list[0]
        else:
            ans_num += use_list[1]
            for i in range(len(num)):
                ans_num += use_list[0]
    
    return ans_num
    
def main():
    print(solve(data[0], num_list))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  list(map(int, input().split()))
    for i in range(n, 10**6):
        s = str(i)
        for d in ds:
            if str(d) in s:
                f = False
                break
            else:
                f = True
        if f:
            print(i)
            sys.exit()
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# encoding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))

Db = []
for Di in range(10):
    if Di not in D: Db.append(Di)
# print("#", Db)

for level in range(6):
    if N // (10 ** level) < 1: break
# print("#", level)
    
# memo = [None] * ((level + 1) * 10000)
    
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos > level or tmp >= N:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else: return 10000
    # elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10 ** pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    # if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    
    return ret

print(pay(0, 0))

Submission status: Accepted

Solution code:
# encoding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))

Db = []
for Di in range(10):
    if Di not in D: Db.append(Di)
# print("#", Db)

for level in range(6):
    if N // (10 ** level) < 1: break
# print("#", level)
    
memo = [None] * ((level + 1) * 10000)
    
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos > level or tmp >= N:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else: return 10000
    elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10 ** pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    
    return ret

print(pay(0, 0))

Submission status: Accepted

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

for i in range(N, 10000 * 10):
    if len(set(str(N)) & D) >= 1:
        N += 1
    else:
        print(N)
        break

Submission status: Accepted

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

    while any(c in ds for c in iter(str(n))):
        n += 1

    print(n)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n, k = map(int, input().split())
D = [int(x) for x in input().split()]


def dfs(s: str, m: int) -> None:
    if s != "" and int(s) >= n:
        print(s)
        sys.exit()

    if len(s) == m:
        return

    for i in range(10):
        if i not in D:
            dfs(str(i) + s, m)


for i in range(sys.maxsize):
    dfs("", i)

Submission status: Accepted

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

for i in range(10**6):
    if len(set(str(N)) & D) >= 1:
        N += 1
    else:
        print(N)
        break

Submission status: Accepted

Solution code:
import itertools
N,K = input().split()
D = list(map(int,input().split()))
int_list = set(range(10))
like = list(int_list - set(D))
like.sort()
min_cost = 10**6
for e in itertools.product(like,repeat = len(N)):
    result = 0
    for i in range(len(N)):
        result += e[i] * pow(10,i)
    if int(N) <= result < min_cost:
        min_cost = result
if min_cost == 10**6:
    head = like[0] if like[0] > 0 else like[1]
    min_cost = head * pow(10,len(N))
    for i in range(len(N)):
        min_cost += like[0] * pow(10,i)
print(min_cost)

Submission status: Accepted

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

for i in range(N,10**10):
    if set(str(i)) & D==set():
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = input().split()
D_inv = set([str(i) for i in range(10)]) - set(D)

ans = n
while not set(list(str(ans))).issubset(D_inv):
    ans += 1
print(ans)

Submission status: Accepted

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

N = [int(x) for x in list(str(n))]
D_inv = sorted(list(set(range(10)) - set(D)))

m = len(N) + 1 # 置換する桁
for i in range(len(N)):
    if N[i] in D:
        m = i
        break

if m == len(N) + 1:
    print(n)
    exit()

n = len(N) + 1 # 置換可能な桁 
for i in range(m + 1):
    if N[i] < D_inv[len(D_inv) - 1]:
        n = i

ans = 0
if n == len(N) + 1: # 置換可能な桁がない場合
    if D_inv[0] == 0:
        ans += D_inv[1] * (10 ** len(N))
    else:
        ans += D_inv[0] * (10 ** len(N))
    for i in range(len(N)):
        ans += D_inv[0] * (10 ** (len(N) - 1 - i))
else:
    for i in range(len(N)):
        if i < n:
            ans += N[i] * (10 ** (len(N) - 1 - i))
        if i == n: 
            for j in D_inv:
                if j > N[i]:
                    ans += j * (10 ** (len(N) - 1 - i))
                    break
        if i > n:
            ans += D_inv[0] * (10 ** (len(N) - 1 - i))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split(" "))
list_num = ["0","1","2","3","4","5","6","7","8","9"]
D =  input().split(" ")

use_num = list(set(list_num) - set(D))
ok = []

for a in use_num:
    ok.append(a)
    for b in use_num:
        ok.append(a+b)
        for c in use_num:
            ok.append(a+b+c)
            for d in use_num:
                ok.append(a+b+c+d)
                for e in use_num:
                    ok.append(a+b+c+d+e)
ans = []
for i in ok:
    if int(i) >= N:
        ans.append(int(i))

print(min(ans))

Submission status: Accepted

Solution code:
N, K = [int(_) for _ in input().split()]
D = [int(_) for _ in input().split()]
for i in range(N, 100000):
    is_possible = True
    for d in D:
        if str(d) in str(i):
            is_possible = False
            break
    if is_possible:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ok = [1 for i in range(10)]
for i in range(len(d)):
    ok[d[i]] = -1
for i in range(n, 100000):
    complete = True
    for j in range(len(str(i))):
        if ok[int(str(i)[j])] == -1:
            complete = False
            break
    if complete:
        print(i)
        exit()

"""
import copy
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ok = [1 for i in range(10)]
for i in range(len(d)):
    ok[d[i]] = -1
# nをしたの位から順に置き換えていく
money = [0]
for i in range(len(str(n))):
    money.append(int(str(n)[i]))
# 最小でなくともn以上の整数を作る
for i in reversed(range(1, len(money))):
    for j in range(money[i], 10+money[i]):
        _j = j % 10
        if ok[_j] == 1:
            if _j >= money[i]:
                money[i] = _j
                break
            else:
                money[i] = _j
# print("okList:{}".format(ok))
# print(money)
while True:
    if money[0] != 0:
        break
    else:
        del(money[0])
# print(money)
# 次に可能な限り最小化していく
for i in range(len(money)):
    for j in range(10):
        if ok[j] == 1:
            tmpMoney = copy.deepcopy(money)
            tmpMoney[i] = j
            # print("n:{} tmpMoney:{}".format(n, int(listToString(tmpMoney))))
            if int(listToString(tmpMoney)) >= n:
                # print("money:{}".format(money))
                money[i] = j
                break
print(int(listToString(money)))
"""

Submission status: Accepted

Solution code:
import sys

N, K = map(int, input().split())
D = [str(i) for i in input().split()]
ans = 0
now = N

for j in range(10**6):
    for i in list(str(now)):
        if i in D:
            now += 1
            break
    else:
        print(now)
        sys.exit()

Submission status: Accepted

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

m = {}
for i in range(10):
    has_num = False
    for d in D:
        if d == i:
            has_num = True
            break
    if has_num:
        m[i] = True
    else:
        m[i] = False

min_cost = N
while(True):
    min_cost_list = list(str(min_cost))
    num_list = [int(i) for i in min_cost_list]
    has_num = False
    for n in num_list:
        if m[n]:
            has_num = True
    if has_num:
        min_cost += 1
        continue
    else:
        break
print(min_cost)

Submission status: Accepted

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


while True:
	is_okay = True
	for n in hate_numbers :
		if (str(N).find(n) == -1) :
			continue
		is_okay = False
		break
	
	if (is_okay == True) :
		print(N)
		break
	else :
		N += 1

Submission status: Accepted

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

p = N
flag = True
while flag:
  pnum = list(map(int, str(p)))
  bp = [(i in D) for i in pnum]
  flag = sum(bp)
  if flag:
    p += 1
  
print(p)

Submission status: Accepted

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

usable = set([str(i) for i in range(10)]) - set(D)
# print(usable)

for i in range(N, 10000*10):
    if set(list(str(i))).issubset(usable):
        print(i)
        break

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()
    D = li_input()

    price = N
    while True:
        dislike = False
        for p in str(price):
            if int(p) in D:
                dislike = True
                break
        
        if not dislike:
            print(price)
            return
        
        price += 1
        


main()

Submission status: Accepted

Solution code:
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])
    usable_set = set(range(0, 10)) - hate_set
    
    while True:
        if all(map(lambda x: int(x) in usable_set,
                   [int(str(price)[i]) for i in range(len(str(price)))])) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print(abc042_c())

Submission status: Accepted

Solution code:
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    while True:
        if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
                   [int(str(price)[i]) for i in range(len(str(price)))])) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print(abc042_c())

Submission status: Accepted

Solution code:
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    ans = price

    while True:
        if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
                   [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
            return ans

        ans += 1


if __name__ == '__main__':
    print(abc042_c())

Submission status: Accepted

Solution code:
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    usable_list = list(set(range(0, 10)) - hate_set)

    ans = 0

    while True:
        if all(map(lambda x: int(x) in usable_list, [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
            return ans

        ans += 1


if __name__ == '__main__':
    print(abc042_c())

Submission status: Accepted

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

flag = 0
while flag == 0 :
    counter = 0
    for c in str(N) :
        if c not in L :
            counter += 1
        else :
            break
    if counter == len(list(str(N))) :
        flag = 1
    else :
        N += 1
print(N)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
L = list(map(str,input().split()))
flag = 0
while flag == 0 :
    counter = 0
    for c in str(N) :
        if c not in L :
            counter += 1
        else :
            break
    if counter == len(list(str(N))) :
        flag = 1
    else :
        N += 1
print(N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
Dk = list(map(int, input().split()))

all = [i for i in range(10)]

for Di in Dk:
    if Di in all:
        all.remove(Di)

# print(all)
ans = 0
for i in range(N,100000):
    tmp_list = map(int, list(str(i)))
    # print(tmp_list)
    all_ok = True
    for c in tmp_list:
        if c in all:
            pass
        else:
            all_ok = False
            continue
    if all_ok == True:
        ans = i
        break

print(ans)

Submission status: Accepted

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


def hate_num(n):
    for s in str(n):
        if int(s) in D:
            return False
    return True

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

Submission status: Accepted

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

while True:
  N = set([int(i) for i in str(n)])
  if len(N.intersection(d)) == 0:
    print(n)
    break
  else:
    n += 1

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = input().split()
price = n
ans = n
while True:
    flg = True
    for let in d:
        if str(n).count(let) > 0:
            flg = False
            break
    if flg != False:
        ans = n
        break
    n += 1
print(ans)

Submission status: Accepted

Solution code:

def solve(N, K, Ds):
    while True:
        c = set([int(c) for c in str(N)])
        if len(c.intersection(Ds)) == 0:
            return N
        N += 1


if __name__ == "__main__":
    N, K = map(int, input().split(" "))
    Ds = set(map(int, input().split(" ")))
    print(solve(N, K, Ds))

Submission status: Accepted

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

N, K = map(int, input().split())
D = list(map(str, input().split()))
flag = True
while flag:
    list_N = list(str(N))

    for num in D:
        if num in list_N:
            flag = True
            N += 1
            break
        else:
            flag = False
print(N)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    input_d = set(input().split())

    while True:
        n = set(list(str(N)))
        if not input_d & n:
            break
        N += 1
    print(N)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()
    D = input().split()

    c_money = N

    while True:
        is_dislike = False

        for a in set(str(c_money)):
            if a in D:
                is_dislike = True
                break
        
        if is_dislike:
            c_money += 1
        else:
            print(c_money)
            return


main()

Submission status: Accepted

Solution code:
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession
# 参考 : https://abc042.contest.atcoder.jp/submissions/3419872

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    while len(set(list(str(x))) & d) != 0:
        x += 1
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D)
    print(amount)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c, num = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
t = True
while t:
    for x in arr:
        if str(x) in str(c):
            break
    else:
        t = False
        break
    
    c += 1
    
if not t:
    print(c)

Submission status: Accepted

Solution code:
N,k=map(int,input().split())
K=list(map(str,input().split()))
        
for i in range(N,N+99999):
    cnt=0
    for j in range(k):
        if K[j] in str(i):
            cnt+=1
    if cnt==0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
a = input().split(" ")
ar = input().split(" ")
count = 0
k = 0
n = int(a[0])-1
while count != 1:
    n += 1
    for b in ar:
        if b in str(n):
            k += 1
    if k == 0:
        count += 1
    k = 0
print(n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
frag = True
ans = 0
N = N-1
for i in range(0, 1000000):
    N += 1
    if len(set(str(N)) & D) == 0:
        ans = N
        frag = False
        break
print(N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split());d=input().split()
while 1:
    for c in str(n):
        if c in d:break
    else:
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
import sys


def exists_allow(string, not_list):
    for i in not_list:
        if string.count(str(i)) > 0:
            return True
    return False


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

while True:
    if exists_allow(str(n), d):
        n = n + 1
    else:
        print(n)
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D=input().split()
for i in range(N,100001):
    dame=False
    for d in D:
        if d in str(i):
            dame=True
            break
    if dame:
        continue
    else:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    D = list(input().split())
    for n in count(N):
        ok = True
        for c in str(n):
            if c in D:
                ok = False
                break
        if ok:
            print(n)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = n
ans_list = list(str(ans))
while True:
    ans_list = list(str(ans))
    for number in ans_list:
        if number in list_d:
            ans += 1
            break
    else:
        print(ans)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
array = {int(x) for x in input().split()}
mihon = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}^array

for i in range(n, 100001):
    tmp = list(str(i))
    tmp = {int(x) for x in tmp}
    if tmp.issubset(mihon) and i >= n:
        print(i)
        break

Submission status: Accepted

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

sw = False

while True:
    N_str = str(N)
    
    for i in N_str:
        if i in hate:
            break
    else:
        sw = True
    
    if sw:
        print(N)
        break
    
    N += 1

Submission status: Accepted

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

Submission status: Accepted

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

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

i = N
while i >= N:
  work = i
  while work > 0:
    if work % 10 in D:
      break
    else:
      work = work // 10

  if work > 0:
    i += 1
    continue
  else:
    break
    
print(i)

Submission status: Accepted

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

def isValid(num):
    s = str(num)
    for c in s:
        if c in d:
            return False
    return True

for i in range(n,10*n+1):
    if isValid(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
aUnList.sort()
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iL,iPoint,aUnList,aRet,bRev):
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    aUpper.sort()
    if bRev: #逆行
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 : #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * (iL + 1)
            else:
                return fCheckDigit(sTarget,iL,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            return aRet[0:iPoint]+[str(aUpper[1])]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がないときは逆行して調べる
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iL,iPoint-1,aUnList,aRet,True) #逆行する
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iL,iPoint+1,aUnList,aRet,False) #順行する
                else:
                    return aRet

print( ''.join(fCheckDigit(sN,len(sN),0,aUnList,[],False)))