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

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



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



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



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



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

Solution (Python):




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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):
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,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    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,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,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,iPoint+1,aUnList,aRet,False) 
                else:
                    return aRet

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

Solution (Python):
N, K = map(int, input().split())
D = [str(_) for _ in input().split()]
Unable = set(D)

Fin = False
Ans = N
while not Fin:
    if not set(str(Ans)) & Unable:
        Fin = True
    else:
        Ans += 1

print(Ans)

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
while True:
    p = 0
    for s in d:
        if str(s) in str(n):
            pass
        else:
            p += 1
    if p==k:
        print(n)
        break
    else:
        n += 1

Solution (Python):
n,d = map(int,input().split())
lis = list(map(str,input().split()))
cou = n
while 1:
  for i in range(d):
    if lis[i] in str(cou):
      break
    if i == d-1:
      print(cou)
      exit()
  cou += 1

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = N
while True:
    i = n
    while i != 0:
        if i % 10 in D:
            break
        i = i // 10
    if i == 0:
        break
    n += 1
print(n)

Solution (Python):



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

for i in range(n, 100000):
    f = True
    for si in str(i):
        if int(si) in d:
            f = False
    if f:
        print(i)
        break

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
notD = [i for i in range(0, 10)]
for i in D:
    notD[i] = 10
i = 0
while True:
    if i >= len(notD):
        break
    if notD[i] == 10:
        del notD[i]
        i -= 1
    i += 1
i = N
while True:
    ans = 1
    for j in list(str(i)):
        for k in D:
            if int(j) == k:
                ans = -1
                break
        if ans == -1:
            break
    if ans == -1:
        i += 1
    elif ans == 1:
        print(i)
        break

Solution (Python):
N, K = map(int, input().split())
inputs_set = set([i for i in input().split()])

all_set = set({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})
rest_set = all_set - inputs_set

for i in range(N, N*10 + 1):
    if set(str(i)) <= rest_set:
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
for i in range(n, 10 * n + 1):
    flag = True
    q = str(i)
    for j in range(len(q)):
        if int(q[j]) in d:
            flag = False
            break
    if flag:
        print(i)
        break

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

start = N
while True:
    for num in str(start):
        if num in lst:
            break
    else:
        break
    start += 1
print(str(start))

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

n = N

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

print(n)

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

n = N

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

print(n)

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

n = N

while True:
    i = n
    while i != 0:
        if i % 10 in D:
            break
        i = int(i / 10)
    if i == 0:
        break
    n += 1

print(n)

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

n = N

while True:
    i = n
    while i != 0:
        if i % 10 in D:
            break
        i = i // 10
    if i == 0:
        break
    n += 1

print(n)

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

n = N

while True:
    flg = False
    for Di in D:
        if str(Di) in str(n):
            flg = True
    if not flg:
        break
    n += 1

print(n)

Solution (Python):
n,k = map(int,input().split())
hate_nums = list(input().split())
affordable = n

while True:
    is_hate = False
    for digit in list(str(affordable)):
        if digit in hate_nums:
            is_hate = True
    if is_hate:
        affordable += 1
    else:
        print(affordable)
        break

Solution (Python):
from itertools import product

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


def check(x):
    for s in str(x):
        if int(s) in D:
            return False
    return True


for i in range(N, 10 * N):
    if check(i):
        print(i)
        break

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

for n in range(N, 1000000000):
    n = str(n)
    flag = True
    for ni in n:
        if ni in D:
            flag = False
            break
    if flag:
        print(n)
        exit()

Solution (Python):
n,k=map(int, input().split())
d=list(input().split())
x=n
while(1):
    j=False
    for t in list(str(x)):
        if t in d:
            j=True
    if j:
        x+=1
    else:
        print(x)
        break

Solution (Python):
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(a)

Solution (Python):
N, L = map(int, input().split())
D = input().split()
ans = N
while 1:
    s = str(ans)
    f = 1
    for i in D:
        if i in s : f = 0
    if f : break
    ans += 1
print(ans)

Solution (Python):
def main():
    N, L = map(int, input().split())
    D = input().split()
    ans = N
    while 1:
        s = str(ans)
        f = 1
        for i in D:
            if i in s : f = 0
        if f : break
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, L = map(int, input().split())
    D = input().split()
    ans = N
    while 1:
        s = str(ans)
        if not [1 for i in D if i in s] : break
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import itertools

n, k = map(int, input().split())
array = {x for x in input().split()}
num_array = {str(x) for x in range(10)}
like_num = array^num_array

res = float("inf")
for i in range(1, 100000):
    tmp = set(list(str(i)))
    if tmp.issubset(like_num):
        if n <= i < res:
            res = i
print(res)

Solution (Python):


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

for i in range(N, 100000):
    i = str(i)
    for j in range(K):
        if i.find(Dk[j]) != -1:
            break
        if j == K-1:
            print(i)
            exit()

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

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

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

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

Solution (Python):
N, K=map(int,input().split())
D=list(map(int,input().split()))
ans=N
while ans<99999:
    flag=False
    num = list(map(int, str(ans)))
    for i in range(K):
        for digit in num:
            if digit==D[i]:
                ans +=1
                flag=True
                break
        if flag:
            break
    if flag==False:
        break
print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,K = inpl()
dd = inpl()

def check(N):
	tmp = list(map(int,list(str(N))))
	for t in tmp:
		if t in dd:
			return False
	return True

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

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

s = set(d)

N = str(n)
flag = 1
for i in N:
    if int(i) in s:
        flag = 0

if flag:
    print(n)
else:
    while True:
        n += 1
        N = str(n)
        flag = 1
        for i in N:
            if int(i) in s:
                flag = 0
        if flag:
            print(n)
            break

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

ans = 0

for i in range(N, 10*N+1):
    res = i
    while res > 0:
        digit = res % 10
        
        if digit in D:
            break
        
        res //= 10
        
    if res <= 0:
        ans = i   
        break

print(ans)

Solution (Python):
N,K=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
INF = 99999999

for i in range(N,INF):
	for d in D:
		if str(d) in str(i):
			break
	else:
		print(i)
		break

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

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

Solution (Python):


def main():
    
    n, k = map(int, input().split())
    d_list = list(map(int, input().split()))

    while True:
        if all(x not in d_list for x in list(map(int, list(str(n))))):
            ans = n
            break
        n += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

import itertools

def solve(like_list, n, rp,  ans):
    for i in itertools.product(like_list, repeat=rp):
        if i[0] != 0:
            num = int(''.join(map(str, i)))
            if num >= int(n):
                ans = min(ans, num)
    return ans

def main():
    n, k = input().split()
    d_list = list(map(int, input().split()))

    like_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in d_list:
        like_list.remove(i)
    ans = float('inf')
    ans = solve(like_list, n, len(n), ans)
    if ans == float('inf'):
        ans = solve(like_list, n, len(n)+1, ans)

    print(ans)

if __name__ == '__main__':
    main()

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

def check(a):
    s = str(a)
    for i in s:
        if int(i) in D: return True
    return False

n = N
while check(n):
    n += 1
print(n)

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

Solution (Python):

"""
Created on Sat Aug  4 15:31:00 2018

@author: maezawa
"""

n, k = list(map(int, input().split()))
d = frozenset(list(map(str, input().split())))
ok = frozenset(list(map(str,range(10)))) - d

for i in range(n, 100000):
    if frozenset(str(i)) <= ok:
        print(i)
        break

Solution (Python):
from itertools import product as p

n,k=map(int,input().split())
e={i for i in range(10)}
d=e^set(map(int,input().split()))
f=lambda x:int("".join(map(str,x)))
g=lambda x:x>=n
h=sorted(filter(g,map(f,p(d,repeat=len(str(n))))))
if h:
  print(h[0])
else:
  h=sorted(filter(g,map(f,p(d,repeat=len(str(n))+1))))
  print(h[0])

Solution (Python):
N, K = [int(i) for i in input().split()]
D = [s for s in input().split()]
ans = N

while(True):
    for i in range(len(str(ans))):
        if str(ans)[i] in D:
            ans += 1
            break
    else:
        break
print(ans)

Solution (Python):
N, K = input().split()
D = [int(x) for x in input().split()]
L = [str(i) for i in range(10) if i not in D]
ANS = ''
for i, n in enumerate(N):
  if n in L:
    ANS += n
  elif int(L[-1]) > int(n):
    ANS += [l for l in L if int(l) > int(n)][0]
    ANS += L[0] * (len(N) - len(ANS))
    break
  else:
    while ANS:
        c = ANS[-1]
        ANS = ANS[:-1]
        if int(L[-1]) > int(c):
          ANS += [l for l in L if int(l) > int(n)][0]
          break
    if ANS:
      ANS += L[0] * (len(N) - len(ANS))
    else:
      ANS = (L[0] if int(L[0]) else L[1]) + L[0] * len(N)
    break
print(ANS)

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

while any(x in D for x in str(N)): N += 1
print(N)

Solution (Python):

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


    ans = n

    Flag = False
    while True:
        for i in range(k):
            if list(str(ans)).count(d[i]) > 0:
                ans+=1
                Flag = True
                break
            if i == k -1:
                print(ans)
                exit()


if __name__ == "__main__":
        main()

Solution (Python):

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


    ans = n

    Flag = False
    while True:
        for i in range(k):
            if list(str(ans)).count(d[i]) > 0:
                ans+=1
                Flag = True
                break
            if i == k -1:
                print(ans)
                exit()


if __name__ == "__main__":
        main()

Solution (Python):
N, K = map(int, input().split())
D = [Di for Di in input().split()]
for n in range(N, 1000000000):
    n = str(n)
    flag = True
    for i in range(len(str(n))):
        if n[i] in D:
            flag = False
            break
    if flag is True:
        print(n)
        exit()

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

flag = True
while any([i==j for i in list(map(int, list(str(n)))) for j in d]):
    n += 1
print(n)

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

f=1
now=n

while f>0:
    a=[]
    b=now
    while b>0:
        a.append(b%10)
        b=b//10
    f2=-1
    for c in a:
        if c in k:
            f2=1
    if f2>0:
        now+=1
    else:
        f=-1

print(now)

Solution (Python):
n,k = map(int,raw_input().split())

arr = [0,1,2,3,4,5,6,7,8,9]
r = map(int,raw_input().split())

for i in r:
	arr.remove(i)


def count_digit(num):
	count = 0
	t = num 
	while t > 0 :
		count += 1
		t /= 10
	return count

dc = count_digit(n) + 1


ans = float("inf")

def dfs(s,i):
	global ans,n,dc
	
	ret = int(s) if i > 0 else 0
	if ret >= n :
		ans = min(ans,ret)

	if i != dc :
		for j in arr :
			dfs(s + str(j),i + 1)

dfs('',0)
print ans

Solution (Python):
def inpl(): return input().split()
n, k = map(int, inpl())
d = inpl()

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

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

avail = [x for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] if x not in d]

i = 0
while 1 :
    okflg = True
    for c in (str(N + i)) :
        if int(c) not in avail :
            okflg = False
            
    if okflg == True :
        print(N + i)
        break
    i += 1

Solution (Python):
N, K = [int(i) for i in input().split()]
d = [s for s in input().split()]
ans = N

while(True):
    sAns = str(ans)
    for i in range(len(sAns)):
        if sAns[i] in d:
            ans += 1
            break
    else:
        break

print(ans)

Solution (Python):
import itertools

str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)

d = set([int(di) for di in input().split()])
opt = list({0,1,2,3,4,5,6,7,8,9} - d)

def isok(num):
    if set([int(_) for _ in list(str(num))]) - set(opt) == set():
        return True
    else:
        return False

i = 0
while True:
    if isok(n + i):
        print(n + i)
        break
    i += 1

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

while True:
    flag = 1
    N_str = list(str(N))
    
    for s in N_str:
        if int(s) in D:
            flag = 0
            break
    
    if flag:
        print(N)
        break
    
    N += 1

Solution (Python):
import itertools, math

n, k = input().split()
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
length = len(n)
coms = itertools.product(nums, repeat=length+1)
n = int(n)
ans = float("inf")
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

coms = itertools.product(nums, repeat=length)
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

print(ans)

Solution (Python):
import itertools, math

n, k = input().split()
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
length = len(n)
coms = itertools.product(nums, repeat=length)
n = int(n)
ans = float("inf")
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

coms = itertools.product(nums, repeat=length+1)
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)
print(ans)

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
while True:
    change=False
    for i in str(n):
        if int(i) in d:
            n+=1
            change=True
            break
    if change==False:
        break
print(n)

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

Solution (Python):
n, k = map(int, raw_input().split())
d = set(raw_input().split())
found = False
while True:
  a = set(str(n))
  if a & d:
    n += 1
    continue
  else:
    print(n)
    break

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

can = False
while not can:
    can = True
    n_str = str(n)
    for num in n_str:
        if num in d:
            can = False
            n += 1
            break

print(n)

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

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

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

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

Solution (Python):
n, k = (int(char) for char in input().split())
d = [int(i) for i in input().split()]

'''
n = 10
k = 8
d = [0, 2, 3]
'''
D = [i for i in range(10)]

like_vals = [int(str(i)) for i in D if i not in d]

i = 0

n = [int(str(n)[i]) for i in range(len(str(n)))]
r = [-1] * len(n)
while i < len(n):
    if n[i] in like_vals:
        r[i] = n[i]
        i += 1
    elif n[i] < max(like_vals):
        like_bigger = [like_val for like_val in like_vals if like_val > n[i]]
        r[i] = min(like_bigger)
        for j in range(i + 1, len(n)):
            r[j] = min(like_vals)
        break
    else:
        r = [-1] * (len(n) + 1)
        if min(like_vals) != 0:
            r[0] = min(like_vals)
        else:
            r[0] = min([like_val for like_val in like_vals if like_val != 0])

        for j in range(1, len(n) + 1):
            r[j] = min(like_vals)
        break

newr = ""
for _r in r:
    newr += str(_r)
newr = int(newr)
print(newr)