CodeEff/ECCO huggingface dataset:
# Original solution
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = set(LI())
# 最小金額から条件を満たすまで増やしていく
while True:
    if all([int(j) not in d for j in str(n)]):  # 全ての桁の数字が d に属さない
        print(n)
        exit()
    n += 1


# Optimized solution
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = set(LI())
# 最小金額から条件を満たすまで増やしていく
while True:
    if all(int(j) not in d for j in str(n)):  # 全ての桁の数字が d に属さない
        print(n)
        exit()
    n += 1
# Original solution
import itertools
n, k = input().split()
d = list(map(int, input().split()))

number = list(range(10))
number = [str(x) for x in number if x not in d]

ans = []
for v in itertools.product(number, repeat=len(n)):
  if v[0] == "0": continue
  if int("".join(v)) >= int(n): ans.append(int("".join(v)))

if not ans:
  for v in itertools.product(number, repeat=len(n)+1):
    if v[0] == "0": continue
    if int("".join(v)) >= int(n): ans.append(int("".join(v)))

print((min(ans)))

# Optimized solution
import itertools
n,k = list(map(int, input().split()))
d = list(input().split())
d = [str(i) for i in range(10) if str(i) not in d]

ans = float("INF")
for v in itertools.product(d, repeat=len(str(n))):
  if v[0] != "0" and int("".join(v)) >= n:
    if ans > int("".join(v)): ans = int("".join(v))
if ans == float("INF"):
  for v in itertools.product(d, repeat=len(str(n))+1):
    if v[0] != "0" and int("".join(v)) >= n:
      if ans > int("".join(v)): ans = int("".join(v))
print(ans)
# Original solution
n, k = list(map(int, input().split()))
dlist = [s for s in input().split()]
ans = n
while True:
    blnOk = True
    for d in str(ans):
        if d in dlist:
            blnOk = False
    if blnOk:
        print(ans)
        exit()
    else:
        ans += 1


# Optimized solution
n, k = list(map(int, input().split()))
dlist = [s for s in input().split()]
ans = n
while True:
    blnOk = True
    for d in str(ans):
        if d in dlist:
            blnOk = False
            break
    if blnOk:
        print(ans)
        exit()
    else:
        ans += 1
# Original solution
a,b = list(map(int,input().split())) 
li1 = set(map(int,input().split()))
li2 = {1,2,3,4,5,6,7,8,9,0}
nu = list(li1^li2)

i = 1
while True:
    aa = list(str(a))
    aa = [int(x) for x in aa]
    if set(aa).issubset(set(nu)):
        print(a)
        break
    a += i

# Optimized solution
n,k = list(map(int,input().split()))
L = list(map(int,input().split()))
num = [1,2,3,4,5,6,7,8,9,0]
li = list(set(num).difference(set(L)))

flag = False
while True:
    n = str(n)
    for i in range(len(n)):
        if int(n[i]) in li:
            flag = True
        else:
            flag= False
            break
    if flag:
        print(n)
        exit()
    n = int(n)
    n +=1
# Original solution
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))

#使うことのできるリストの作成
d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i): #数値iがdのリストだけで書くことができるかを判定
    I = str(i) #文字列に変換
    # print (I)
    n = len(I) #桁数の取得
    for j in range(n): #全桁で確認
        # print (I[j])
        if int(I[j]) in d: #大丈夫ならスルー
            pass
        else: #一つでも不適ならFalseを返す
            return False
    return True

# print (check(2000))

for i in range(N, 10**5 + 1): #小さい数から全探索
    if i >= N: #大きさを確認
        if check(i): #dの中だけで書けるかをチェック
            print (i) #書くことができるなら出力して終了
            exit()


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

#使うことのできるリストの作成
d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i): #数値iがdのリストだけで書くことができるかを判定
    I = str(i) #文字列に変換
    # print (I)
    n = len(I) #桁数の取得
    for j in range(n): #全桁で確認
        # print (I[j])
        if int(I[j]) in d: #大丈夫ならスルー
            pass
        else: #一つでも不適ならFalseを返す
            return False
    return True

# print (check(2000))

for i in range(N, 10**5 + 1): #小さい数から全探索
    if check(i): #dの中だけで書けるかをチェック
        print (i) #書くことができるなら出力して終了
        exit()
# Original solution
N,K = list(map(int,input().split()))
D = set(input().split())
while True:
    if not set(str(N)) & D:
        break
    N += 1
print(N)

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

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

print(i)
# Original solution
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
C=[]

for i in range(0,10):
  if i not in D:
    C.append(i)
#print(C)

for i in range(N,10**10):
  cnt=0
  for j in list(map(int,list(str(i)))):
    if j in C:
      cnt+=1
  if len(str(i))==cnt:
    print(i)
    exit()

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

for i in range(N, 10 * N + 1):
  A = list(map(int, str(i)))
  flag = 1
  for a in A:
    if a in D:
      flag = 0
      break
  if flag:
    print(i)
    exit()
# Original solution
numbers = {str(i) for i in range(10)}
N, K = list(map(int, input().split()))
*D, = list(map(str, input().split()))
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

# Optimized solution
n, k = list(map(int, input().split()))
d = set(map(str, input().split()))
numbers = {str(i) for i in range(10)}
available = numbers - d
for i in range(n, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break
# Original solution
N, K = list(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)

# Optimized solution
N, K = list(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)
# Original solution
N, K = list(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)

# Optimized solution
N, K = list(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)
# Original solution
N, K = list(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)

# Optimized solution
N, K = list(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)
# Original solution
N, K = list(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)

# Optimized solution
import sys

n, k = list(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)
# Original solution
N,K = list(map(int,input().split()))
D = set(input().split())
while 1:
    E = set(str(N))
    if not(D&E):
        print(N)
        break
    N+=1

# Optimized solution
N,K = list(map(int,input().split()))
D = list(input().split())
for i in range(N,100001):
    n = str(i)
    k = 1
    for j in n:
        if j in D:
            k=0
            break
    if k:
        print(n)
        break
# Original solution
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))

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

for _d in d:
    use.remove(_d)


while True:
    ok = True
    s = str(n)
    for i in range(len(s)):
        if int(s[i]) not in use:
            ok = False
            break

    if ok:
        print(n)
        exit()
    else:
        n += 1



# Optimized solution
n, k = list(map(int, input().split()))
D = list(map(str, input().split()))
money = n
ok = True
while True:
    for d in D:
        if d in str(money):
            ok = False
            break
    if ok:
        print(money)
        break
    money += 1
    ok = True
# Original solution
n,k = list(map(int,input().split()))
d = list(map(int,input().split()))

while True:
    a = []
    m = n
    while m > 0:
        a.append(m % 10)
        m = m // 10
    
    j = 0
    for i in range(len(a)):
        if a[i] in d:
            break
        j += 1
        
    if j == len(a):
        print(n)
        exit(0)
    else:
        n += 1

# Optimized solution
n,k = list(map(int,input().split()))
d = list(input().split())
flg = True
while flg:
    flg = False
    m = list(str(n))
    for i in m:
        if i in d:
            flg = True
            break
    if flg:
        n += 1
print(n)
# Original solution
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=list(map(int, input().split()))
d=list(map(str, input().split()))
for item in d:
    a.remove(item)
#print(a)

from collections import deque

q=deque()
q.extend(a)
for i in range(len(a)):
    if int(a[i])>=n:
        print((a[i]))
        sys.exit()

while True:
    qq=q.popleft()
    #print(q)
    for item in a:
        qqq=qq+item
        #print(qqq[::-1])
        if int(qqq[::-1])>=n:
            print((qqq[::-1]))
            sys.exit()
        q.append(qqq[::-1])


# Optimized solution
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=list(map(int, input().split()))
d=list(map(str, input().split()))
for item in d:
    a.remove(item)
#print(a)

from collections import deque

q=deque()
q.extend(a)
for i in range(len(a)):
    if int(a[i])>=n:
        print((a[i]))
        sys.exit()

while True:
    qq=q.popleft()
    #print(q)
    for item in a:
        qqq=qq+item
        #print(qqq[::-1])
        if int(qqq)>=n:
            print(qqq)
            sys.exit()
        q.append(qqq)
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    
    while(True):
        nl = list(map(int,list(str(N))))
        f = True
        for i in range(len(nl)):
            if(nl[i] in D):
                f = False
        if(f):
            print(N)
            exit()
        else:
            N += 1

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    d = set(map(str, D))
    while set(str(N))&d:
        N += 1

    print(N)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()
# Original solution
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    global ans
    if n != '' and n[0] == '0':
        return
    if n != '' and int(n) >= ans:
        return
    if len(n) >= len(str(N)):
        if int(n) >= N:
            ans = int(n)
    for l in L:
        dfs(n + str(l))


dfs('')
print(ans)

# Optimized solution
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]


def dfs(n):
    if n != '':
        if n[0] == '0':
            return 10 ** 7
        elif int(n) >= N:
            return int(n)
    output = 10 ** 7
    for l in L:
        output = min(output, dfs(n + str(l)))
    return output


print((dfs('')))
# Original solution
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0
 
solve()

# Optimized solution
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))

def solve():
  for i in range(10*n+2):
    if i >= n:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in d:
          break
      else:
        print(i)
        return 0

solve()
# Original solution
n,k = list(map(int,input().split()))
D = list(map(int,input().split()))

ans = n
while True:
    for i in list(map(int, str(ans))):
        if i in D:
            break
    else:
        print (ans)
        exit ()

    ans += 1


# Optimized solution
import sys
sys.setrecursionlimit(500000)

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

ans = []
def dfs(p:str):
    if int(p)>=n:
        ans.append(int(p))
        return

    if len(p)>len(str(n))+1:
        return

    for i in range(10):
        if not i in D:
            dfs(p+str(i))

for i in range(10):
    if not i in D:
        dfs(str(i))

print((min(ans)))
# Original solution
# coding: utf-8;

def main():
    num = [0,1,2,3,4,5,6,7,8,9]
    n, k = list(map(int, input().split()))
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))

    while True:
        if len(set(map(int, str(n))) - set(usable_num)) == 0:
            break
        else:
            n += 1
    print(n)

if __name__ == '__main__':
    main()


# Optimized solution
# coding: utf-8;

def main():
    num = [0,1,2,3,4,5,6,7,8,9]
    n, k = list(map(int, input().split()))
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))

    while True:
        f = True
        for a in str(n):
            if int(a) not in usable_num:
                f = False
                break
        if f: break
        n += 1
    print(n)

if __name__ == '__main__':
    main()
# Original solution
N, K = list(map(int, input().split()))  # 標準入力
D = list(map(int, input().split()))  # 嫌いな数字のリスト
D_str = list(map(str, D))
m = N
 
while True:
    for n in str(m):
        if n in D_str:
            break
    else: # breakされなかったら実行される
        print(m)
        break
    m += 1

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

ans=N
while True:
  for i in str(ans):
    if i in D:
      break
  else:
    print(ans)
    exit()
  ans +=1
# Original solution
def main():
    n,k=list(map(int,input().split(' ')))
    d = list(input().split(' '))
    for i in range(n,10*n+1):
        if not set(list(str(i)))&set(d):
            print(i)
            break


main()

# Optimized solution
def main():
    n,k=list(map(int,input().split(' ')))
    d = input().split(' ')
    for i in range(n,10*n+1):
        if not set(list(str(i)))&set(d):
            print(i)
            break

if __name__=='__main__':
    main()
# Original solution
def main():
    from sys import stdin
    n,k = list(map(int,stdin.readline().rstrip().split()))
    Ds = set(map(int,stdin.readline().rstrip().split()))

    ans = n
    while True:
        num = ans
        numset = set()
        while num != 0:
            r = num%10
            num = num//10
            numset.add(r)
        if numset & Ds == set({}):
            break;
        else:
            ans+=1
    
    print(ans)
main()

# Optimized solution
import io,sys
sys.setrecursionlimit(10**6)

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

    while True:
        temp = n
        num = []
        while temp > 0:
            num.append(temp%10)
            temp//=10
        
        flag = True
        for i in num:
            if i in D:
                flag = False
                break
        if flag:
            print(n)
            sys.exit()
        else:
            n+=1
main()
# Original solution
#
# abc042 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)


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

    for i in range(100000):
        if i < N:
            continue
        for d in D:
            if str(i).count(d) != 0:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    # unittest.main()
    resolve()


# Optimized solution
#
# abc042 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000 8
1 3 4 5 6 7 8 9"""
        output = """2000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999 1
0"""
        output = """9999"""
        self.assertIO(input, output)


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

    for i in range(N, 10*N+1):
        for d in D:
            if str(i).count(d) != 0:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    # unittest.main()
    resolve()
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
D = set(range(10)) - set(LI())
for i in range(n, 100000):
    if set([int(j) for j in str(i)]) <= D:
        print(i)
        break







# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
D = set(LI())
for i in range(n, 100000):
    if not set([int(j) for j in str(i)]) & D:
        print(i)
        break
# Original solution
N, K = list(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)
        

# Optimized solution
import sys

N, K = list(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()
# Original solution
N, K = list(map(int, input().split()))
D = [int(i) for i in input().split()]

num = N
flag = True

while flag:
    for i in D:
        if str(i) in str(num):
            num += 1
            break
    else:
        print(num)
        flag = False


# Optimized solution
N, K = list(map(int, input().split()))
D = [str(i) for i in input().split()]
ans = N

for i in range(N, 100001):
    if set(list(str(i))) & set(D):
        gg = 1
    else:
        print(i)
        break
# Original solution
numbers = {str(i) for i in range(10)}
N, K = list(map(int, input().split()))
*D, = list(map(str, input().split()))
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break


# Optimized solution
def problem_c():
    N, K = list(map(int, input().split()))
    D = list(map(str, input().split()))
    numbers = {str(i) for i in range(10)}
    availables = set(numbers) - set(D)

    for i in range(N, 100000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return

##########
problem_c()