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



N,L = map(int,input().split())
mylist = []
mylist = list(map(int,input().split()))







i = 0
result = 0
res_bool = False
while result < 10 * N:
  result = N + i
  
  for a in str(result):
    
    if not a in [str(n) for n in mylist]:
      res_bool = True
    elif a in [str(n) for n in mylist]:
      
      res_bool =False
      break
  
  if res_bool:
    break
  i += 1
  
print(result)

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
ans = N
while True:
    for i in D:
        if str(i) in str(ans):
            break
    else:
        break

    ans += 1

print(ans)

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

s = 0
while s<k and s == d[s]:
    s += 1

x = 0
y = 0
while x <4:
    if n // (10**x) >0:
        y = x
    x += 1

i = 0
a = [0]
m = 0
while i <= y:
    a.append(((n//(10**(y-i)))%10))
    i +=1

i = 0
t = 0
while i <= y + t:
    j = 0
    while j < k:
        if a[y-i+1] == d[j]:
            a[y-i+1] += 1
            if y-i+1 < y+1:
                a[y-i+2] = s
        if a[y-i+1] == 10:
            a[y-i+1] = 0
            a[y-i] +=1
        j+=1
    i+=1
    if a[0] == 1 and t == 0:
        i = 1
        while i<=y+1:
            a[i] = 0
            i += 1
        i = 0
        t = 1
        continue

i = 0
while i <= y + t:
    m += a[y-i+1]*(10**(i))
    i+=1


print(m)

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

for i in range(N,88889):
    for s in str(i):
        if s in D:
            break
    else:
        print(i)
        exit()

Solution (Python):
import itertools
n,k = map(int,input().split())
li = list(map(int,input().split()))
se = list(map(str,set([i for i in range(0,10)]) - set(li)))
lee = len(str(n))
ans = 999999999999999999999
tmp = ''
kumi_li = list(itertools.product(se, repeat=lee+1))
kumi_2_li = list(itertools.product(se, repeat=lee))
for k in kumi_li:
    
    suuji = int(''.join(k))
    if suuji <= ans and suuji >= n:
        ans = suuji
for k in kumi_2_li:
    suuji = int(''.join(k))
    if suuji <= ans and suuji >= n:
        ans = suuji
print(ans)

Solution (Python):
from itertools import product

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
se = set(range(10))
for a in A:
    se ^= set([a])

def check(str_num):
    for x in str_num:
        if not int(x) in se:
            return False
    return True

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

Solution (Python):
import itertools

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

D = set(input().split())

n = [x for x in str(N)]
num = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D
judge = "no"
ans = N

for i in n:
    if i in D:
        judge = "yes"
        break

if judge == "yes":
    if ans < int(sorted(list(num))[-1] * len(n)):
        ans_list = sorted(list(itertools.product(num, repeat=len(n))))
        for i in ans_list:
            if int("".join(i)) > ans:
                ans = int("".join(i))
                break
    else:
        ans_list = sorted(list(itertools.product(num, repeat=len(n) + 1)))
        for j in ans_list:
            if int("".join(j)) > ans:
                ans = int("".join(j))
                break

print(ans)

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

for n in range(N, 100001):
    for s in str(n):
        if s in D:
            break
    else:
        print(n)
        exit()

Solution (Python):
def getDigits(n):
  digits = []
  while n > 0:
    digits.append(n % 10)
    n //= 10
  return digits

def firstValidNumber(n, digits):
  while True:
    isValid = True
    currentDigits = getDigits(n)
    for digit in currentDigits:
      if digit in digits:
        isValid = False
        break
    if isValid:
      return n
    n += 1
  return n

n, k = map(int, input().split())
digits = list(map(int, input().split()))
print(firstValidNumber(n, digits))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = []


def resolve():
    n, k = map(int, input().split())
    D = set(list(map(int, input().split())))
    Available = []

    for i in range(10):
        if i not in D:
            Available.append(str(i))


    def dfs(Price):
        if len(Price) == 5:
           return

        for value in Available:
            Price.append(value)
            res.append(int("".join(Price)))
            dfs(Price)
            Price.pop()

    dfs([])

    ans = f_inf
    for i in res:
        if i >= n:
            ans = min(ans, i)
    
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):

import sys

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

def f():
    q = []

    for i in filter(lambda x: x not in d, range(10)):
        q.append(i)

    while len(q) != 0:
        x = q.pop(0)

        if x >= n:
            print(x)
            break

        for i in filter(lambda x: x not in d, range(10)):
            q.append(x * 10 + i)

f()

Solution (Python):
N, K = map(int, input().split())
D = set(map(str, input().split()))
f = True
while f:
    if set(list(str(N))) == set(list(str(N))) - D:
        print(N)
        f = False
    else:
        N += 1

Solution (Python):
N, K = map(int, input().split())
number =set(map(str, input().split()))
flag = True

while flag == True:   
    temp = list(str(N))
    if set(temp) == set(temp) - number:
        print(N)
        flag = False
    else:
        N = N + 1

Solution (Python):
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            if j+k != 0:
                ans=int(ans)
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
z=set([0])
l2=l-z
if k==1:
    ans+=min(l2)
    ans = int(ans)
for i in range(le):
    ans *=10
    if ans%10 ==0:
        ans+=min(l)
print(int(ans))

Solution (Python):
N, K = input().split()
array = input().split()

result = N
while True:
  for a in array:
    if a in list(result):
      break
  else:
    break
  result = str(int(result) + 1)
print(result)

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

while True:
    str_n = str(n)
    hantei = 1
    for i in range(len(str_n)):
        if int(str_n[i]) in d: hantei = 0
    if hantei == 1: break
    n += 1

print(n)

Solution (Python):
def resolve():
    N, K = list(map(int, input().split()))
    D = input().split()
    i = N
    while True:
        for s in str(i):
            if s in D:
                i += 1
                break
        else:
            print(i)
            return
    raise Exception("unreachable!")

if '__main__' == __name__:
    resolve()

Solution (Python):
n,k=map(int,input().split())
d=set(map(int,input().split()))
d_=set((1,2,3,4,5,6,7,8,9,0))
abl=d_-d
ans=''
a0=True
a1=True
for i in str(n):
  if a0 and int(i) in abl:
    ans+=str(i)
  elif a0:
    b=[ai for ai in abl if int(i)<ai]
    if len(b)==0:
      a1=False
      break
    b.sort()
    ans+=str(b[0])
    a0=False
  else:
    ans+=str(min(abl))
if a1==False:
  print(str(min(abl-{0}))+str(min(abl))*len(str(n)))
else:
  print(ans)

Solution (Python):
def solve(n, k, xs):

    tmp = n
    num = len(xs)
    
    while True:
        if num == len([i for i in xs if i not in str(tmp)]):
            break
        else:
            tmp += 1
    
    return tmp

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    xs = [i for i in input().split()]
    print(solve(n, k, xs))

Solution (Python):
import math
import fractions



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''









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

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

for ii in range(n*10):
    i = ii+1
    ar = ValueToArray10(i, int(1+(math.log(i)+0.00001)/math.log(10)))
    ok=1
    for j in ar:
        for k in a:
            if(j==k):
                ok=0
    if(ok==1 and i>=n):
        print(i)
        exit()

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
d = set(inl())
for i in range(n,100000):
    a = set([])
    j = i
    while j>0:
        a.add(j%10)
        j //= 10
    if len(a&d)==0:
        print(i)
        exit()

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

def split_to1d(x):
  
  res=[]
  while True:
    
    y=x%10
    res.append(y)

    z=x//10
    if z<1:
      break
      
    x=z
  
  return res

while True:
  
  num_list=split_to1d(n)

  for i, num in enumerate(num_list):

    is_ok=True
    if num in nums:
      is_ok=False
      break
     
  if is_ok:
    break
  else:
    n+=1
    
print(n)

Solution (Python):
n, _ = map(int, input().split())
d = set(sorted(map(int, input().split())))

for q in range(100000):
    if not set(sorted({int(str(q)[i]) for i in range(len(str(q)))})) & d:
        if q >= n:
            print(q)
            exit(0)

Solution (Python):
import sys

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

number = N-1
while True:
    number += 1
    ng = False
    for i in range(K):
        if Ds[i] in str(number):
            ng = True
            break

    if ng == False:
        print(number)
        sys.exit(0)

Solution (Python):
n,k = map(int,input().split())
d = list(map(int,input().split()))
sset = set(i for i in range(1,10)) - set(d)

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

Solution (Python):
n,k = map(int, input().split())
d_set = {x for x in input().split()}

for i in range(n, 100000):
    i_set = set(str(i))
    if(len(i_set & d_set) == 0):
        print(i)
        break

Solution (Python):
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    D = set(readline().rstrip().split())
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e in D:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    D = list(map(int, readline().rstrip().split()))
    nums = [str(i) for i in range(10)]
    for d in D:
        nums.remove(str(d))
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e not in nums:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    n, k = map(int, input().split())
    hate = set(input().split())

    while True:
        nset = set(list(str(n)))
        l = nset&hate
        if len(l) == 0:
            print(n)
            break

        n += 1

main()

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

for i in range(n,1000001):
    for j in d:
        if str(i).count(str(j))>=1:
            break
    else:
        print(i)
        exit()

Solution (Python):
if __name__ == '__main__':
    n, k = map(int, input().split())
    lst = list(map(int, input().split()))

    while True:
        flag = True
        for char in str(n):
            if int(char) in lst:
                flag = False
                break
        if flag:
            break
        n += 1
    print(n)

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

check = n
while True:
    can = True
    for letter in str(check):
        if letter in d_ls:
            can = False
    if can:
        break
    check += 1
print(check)

Solution (Python):
cost,n = map(int,input().split())
cash = [int(x) for x in input().split()]


flag = False
while flag == False :
    flag = True
    for i in range(len(cash)):
        if str(cash[i]) in str(cost):
            flag = False
            break
    if flag == False:
        cost += 1
    else:flag=True
        

print(cost)

Solution (Python):

import sys


def solve(N: int, K: int, D: "List[int]"):
    while any([str(i) in str(N) for i in D]):
        N += 1

    print(N)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    D = [int(next(tokens)) for _ in range(K)]  
    solve(N, K, D)

if __name__ == '__main__':
    main()

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

for i in range(n, n*10+1):
    t = str(i)
    isok = True
    for d in D:
        if d in t:
            isok = False
            break
    if isok:
        print(t)
        exit()

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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


def ok(X):
    for d in D:
        if str(d) in str(X):
            return False
    return True

while not ok(N):
    N += 1

print(N)

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

Solution (Python):
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

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

D = set(D)	
number = {'0','1','2','3','4','5','6','7','8','9'}	
out = D^number



out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
        flag = 2
  elif flag == 1:
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
      flag = 2
  elif flag == 2:
    res_list.append(out[0])
        
if flag == 1:
  res_list.append(out[0])  
res = ''
for i in range(len(res_list)):
  res += res_list[i]
print(res)

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

D = set(D)	
number = {'0','1','2','3','4','5','6','7','8','9'}	
out = D^number



out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
        flag = 2
  elif flag == 1:
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
      flag = 2
  elif flag == 2:
    res_list.append(out[0])
        
if flag == 1:
  res_list.append(out[0])  
res = ''
for i in range(len(res_list)):
  res += res_list[i]
print(res)        
    
          
"""
flag = 0
for i in range(len(N)-1, -1, -1):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
  elif flag == 1:
    flag = 0
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
if flag == 1:
  res_list.append(out[0])
  
res = ''
for i in range(len(res_list)-1, -1, -1):
  res += res_list[i]
print(res)
"""

Solution (Python):
def chk(n,arr):
	while n>0:
		if n%10 in arr:
			return True
		n//=10
	return False


n,k = map(int,input().split())
arr = set(list(map(int,input().split())))
while chk(n,arr):
	n+=1
print(n)

Solution (Python):
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def contains_digit(number, digits):
    while number != 0:
        if number%10 in digits:
            return True
        number //= 10
    return False


def solve():
    N, K = read_ints()
    digits = set(read_ints())
    while contains_digit(N, digits):
        N += 1
    return N


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

Solution (Python):
from collections import defaultdict

n, k = map(int, input().split())
d = list(map(int, input().split()))
nums = defaultdict(int)
for i in range(len(d)):
    nums[d[i]] += 1

def judge(n, nums):
    n = str(n)
    for i in range(len(n)):
        if nums[int(n[i])] == 1:
            return False
        
    return True

while 1:
    if judge(n, nums) == True:
        print(n)
        exit()
    n += 1

Solution (Python):
n,l=map(int,input().split())
dis=[i for i in input().split()]
for i in range(n,10*n):
  if set(dis).isdisjoint(str(i)):
    print(i)
    break

Solution (Python):
def check(x,d):
    s=str(x)
    flag=True 
    for i in range(len(s)):
        if int(s[i]) not in d:
            flag=False 
    return flag
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
d=[]
for i in range(10):
    if i not in a:
        d.append(i)
l=len(str(n))
final=10**l 
flag=False

for i in range(n,final):
    
    if check(i,d):
        flag=True
        print(i)
        break 
if not flag:
    if d[0]==0:
        print(str(d[1])+"0"*(l))
    else:
        print(str(d[0])*(l+1))

Solution (Python):
n,k = map(int,input().split())
a = set(map(int,input().split()))
for i in range(n,1000001):
  x = str(i)
  for j in x:
    if int(j) in a:
      break
  else:
    print(i)
    break

Solution (Python):
def abc042_c():
  n, _ = map(int, input().split())
  D = list(map(int, input().split()))
  for i in range(n, 10**5):
    like = True
    for s in str(i):
      if int(s) in D:
        like = False
        break
    if like:
      print(i)
      return

abc042_c()

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

for i in range(N, 10**6):
    if N <= i and len(set(str(i)) & D) == 0:
        print(i)
        exit()

Solution (Python):
n, k = map( int, input().split())
hate = set( input().split())

usable = sorted( list( {str(i) for i in range(10)} - hate))

l = len(str(n))

def check(l):
    num = []
    if l == 1:
        for i in usable:
            num.append(int(i))
    elif l == 2:
        for ii in usable:
            for i in usable:
                num.append(int( ii + i))
    elif l == 3:
        for iii in usable:
            for ii in usable:
                for i in usable:
                    num.append(int( iii + ii + i))
    elif l == 4:
        for iv in usable:
            for iii in usable:
                for ii in usable:
                    for i in usable:
                        num.append(int( iv + iii + ii + i))
    else:
        for v in usable:
            for iv in usable:
                for iii in usable:
                    for ii in usable:
                        for i in usable:
                            num.append(int( str(v) + str(iv) + str(iii) + str(ii) + str(i)))
    return num

truf = False
num = check(l)
for i in num:
    if n <= i:
        print(i)
        truf = True
        break
if not truf:
    num = check(l+1)
    for i in num:
        if n <= i:
            print(i)
            break

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
d = na()
s = str(n)

ans = []
res1 = 0
res2 = 0

while res1 < n:
    if res1 == 0:
        for i in range(1, 10):
            if i not in d:
                res1 *= 10
                res1 += i
                break
    else:
        for i in range(10):
            if i not in d:
                res1 *= 10
                res1 += i
                break

j = 0
while res2 < n:
    ok = False
    for i in range(10):
        if i not in d and res2 * 10 + i >= int(s[:j + 1]):
            res2 *= 10
            res2 += i
            ok = True
            break
    if not ok:
        res2 = inf
        break
    j += 1

print(min(res1, res2))

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  




N, K = read_ints()
D = set(input())

for n in range(N, N + 10 ** 6):
    n_str = str(n)
    for c in n_str:
        if c in D:
            break
    else:
        print(n)
        exit()

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

for i in range(n,100001):
     for x in d:
         if str(x) in str(i):
             break
     else:
         print(i)
         break

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

for i in range(n,n*10+1):
     for x in d:
         if str(x) in str(i):
             break
     else:
         print(i)
         break

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

ans, i, OK = str(N), 0, False
while not OK:
    OK = True
    digit = len(ans)
    for i in range(digit):
        if ans[i] in D:
            k = digit - i - 1
            ans = str((int(ans)//(10**k) + 1)*10**k)
            OK = False
            break
print(ans)

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

n = N
while True:
    d = set(list(str(n)))
    check = D & d
    if len(check) == 0:
        break
    n += 1

print(n)

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

while True:
    for i in str(n):
        flag=True
        if int(i) in d:
            flag=False 
            break
    if flag:
        break
    else:
        n+=1

print(n)

Solution (Python):
n,k = map(int,input().split())
l = list(map(str,input().split()))
for i in range(n,10**7):
  a = [j for j in str(i)]
  if set(a).isdisjoint(set(l)):
    print(i)
    exit()

Solution (Python):
a,n=map(int,input().split())
b=input()
c=[]
for i in range(n):
  c.append(int(b[2*i]))
flag="F"
while flag=="F":
  k=a
  fflag="T"
  while k>=1:
    l=int(k%10)
    for i in range(n):
      if c[i]==l:
        fflag="F"
        break
    k=int(k/10)
    if fflag=="F":
      break
  if fflag=="T":
    flag="T"
  else:
    a+=1
print(a)

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


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

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

    print(N)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
n,k = map(int,input().split())
d = list(map(int,input().split()))
 
for i in range(100000):
    s = str(i)
    n2 = len(s)
    fl = 0
    for j in range(len(s)):
        for k in d:
            if s[j] == str(k):
                fl = 1
                
    if fl == 0:
        if i >= n:
            print(i)
            break

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

p=N

def check(p,D):
  st=str(p)
  for char in st:
    if char in D:
      return False
  else:
    return True
  
while check(p,D)==False:
  p += 1
  
print(p)

Solution (Python):
n, k = map(int, input().split())
list_D = list(map(str, input().split()))
num = n
ans = -1

while True:
    S = list(str(num))
    cnt = 0
    for s in S:
        if s  in list_D:
           cnt += 1
    if cnt == 0:
        ans = num
        break
    num += 1

print(ans)

Solution (Python):
n, k = map(int, input().split())
list_D = set(map(str, input().split()))
num = n
ans = -1

while True:
    S = set(list(str(num)))
    cnt = 0
    for s in S:
        if s  in list_D:
           cnt += 1
    if cnt == 0:
        ans = num
        break
    num += 1

print(ans)

Solution (Python):
N, K = map(int,input().split())
D = set(input().split())
for i in range(N, 100000):
    flag = 1
    for char in str(i):
        if char in D:
            flag = 0
            break
    if flag:
        print(i)
        break

Solution (Python):
def main(data: list):
    [price, numbers] = data
    numbers_set = set(numbers)
    while True:
        unique_price_numbers = set(map(int, list(str(price))))
        common_numbers = numbers_set.intersection(unique_price_numbers)
        if len(common_numbers) == 0:
            print(price)
            break
        price += 1


[N, K] = list(map(int, input().split()))
numbers = [int(v) for v in input().split()]
main([N, numbers])

Solution (Python):


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

while 1:
    flg = 1
    for d in D:
        if d in str(N): flg = 0
    if flg:
        print(N)
        break
    N += 1

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

for i in range(n, 10*n+1):
    for x in d:
        if str(x) in str(i):
            break
    else:
        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):
    for x in d:
        if str(x) in str(i):
            break
    else:
        print(i)
        break

Solution (Python):
def main():
  N, K = (int(_) for _ in input().split())
  D = set(input().split())
  ret = 10 ** 10
  for a in range(10):
    for b in range(10):
      for c in range(10):
        for d in range(10):
          for e in range(10):
            cc = str(int(str(a) + str(b) + str(c) + str(d) + str(e)))
            for s in cc:
              if s in D:
                break
            else:
              if int(cc) >= N:
                ret = min(ret, int(cc))
  print(ret)
  return

if __name__ == '__main__':
  main()

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

for i in range(n,10*n):
    flag=0
    sn=str(i)
    for j in sn:
        if j in d:
            flag=1
    if flag==0:
        print(i)
        exit()

Solution (Python):
from collections import deque
N,K=map(int,input().split())
l=list(map(int,input().split()))
num=[1]*10
nums=[]
d=deque()
ans=[]
for i in range(len(l)):
    num[l[i]]=0
for i in range(10):
    if num[i]==1:
        nums.append(i)
        d.append(i)

for i in range(10000):
    v=d.popleft()
    ans.append(v)
    for j in nums:
        if v!=0:
            d.append(v*10+j)
    
    
    

for i in range(len(ans)):
    if ans[i]>=N:
        print(ans[i])
        break

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

Alist_str = [str(n) for n in Alist]

M=N
while True:
    Mlist_str = list(str(M))
    double = set(Alist_str) & set(Mlist_str)
    if len(double) == 0:
        print(M)
        break
    else:
        M = M +1