CodeEff/ECCO huggingface dataset:
# Original solution
N, K = list(map(int, input().split()))
D = input().split()
for n in range(N, 10 * N):
    if all([c not in D for c in str(n)]):
        print(n)
        break

# Optimized solution
N, K = input().split()
D = input().split()
E = [str(x) for x in range(10) if str(x) not in D]
n = len(N)

next_digit = [(str(d), 0) if str(d) not in D else None for d in range(10)]
for i in range(9, -1, -1):
    if next_digit[i] is None:
        j = (i + 1) % 10
        while next_digit[j] is None:
            j = (j + 1) % 10
        if i < j:
            next_digit[i] = next_digit[j]
        else:
            next_digit[i] = (next_digit[j][0], 1)

for i in range(n):
    if N[i] in D:
        carry = 0
        j = i
        reverse_mid = ""
        while j >= 0:
            d = N[j]
            if carry == 1:
                if d == '9':
                    d = '0'
                else:
                    d = chr(ord(d) + 1)
                    carry = 0
            nd, carry0 = next_digit[int(d)]
            reverse_mid += nd
            carry += carry0
            if carry == 0:
                break
            j -= 1
        if carry == 1:
            head = next_digit[1][0]
        else:
            head = N[:j]
        N = head + reverse_mid[::-1] + (E[0] * (n - 1 - i))
        break
print(N)
# Original solution
def inpl(): return input().split()
n, k = list(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)

# Optimized solution
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    digits = {x for x in range(10)}
    digits -= D
    # print(digits)
    digits = sorted(digits)

    def dfs(pay):
        if pay >= N:
            return pay

        np = pay * 10

        ret = 1 << 60
        if np == 0 and 0 in digits:
            for d in digits:
                if d == 0: continue
                ret = min(ret, dfs(np + d))
        else:
            for d in digits:
                ret = min(ret, dfs(np + d))
        return ret

    print((dfs(0)))


if __name__ == '__main__':
    main()
# Original solution
n,k=list(map(int,input().split()))
d=list(map(int,input().split()))

nmax=100000

for nn in range(n,nmax):
    ns=list(str(nn))
    yn="yes"
    for nsi in ns:
#        print(nn,nsi,(nsi in d))
        if int(nsi) in d:
            yn="no"
            break
    if yn=="no":
        continue
    else:
        break
if yn=="yes":
    print(nn)


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

for nn in range(n,10*n+1):
    if len(set(str(nn)) & d)==0:
        print(nn)
        break
# Original solution
n,k = list(map(int,input().split()))
ng = set(input().split())
while len(set(str(n))&ng):
    n+=1
print(n)
    


# Optimized solution
n,k = list(map(int,input().split()))
ng = set(list(input().split()))
while True:
    if len(set(str(n))&ng)==0:
        break
    else:
        n+=1
print(n)
# Original solution
N, K = list(map(int, input().split()))
D = set(input().split())

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


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

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if test(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y

answer = F(N)
print(answer)
# Original solution
N, K = list(map(int,input().split()))
D = list(map(str, input().split()))

while True:
    S = str(N)
    t = 0
    for x in S:
        if x not in D:
            t += 1
    if t == len(S):
        print(S)
        break
    else:
        N += 1


# Optimized solution
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = list(map(int,input().split()))
    D = set(list(input().split()))
    for k in range(N,100001):
        s = str(k)
        f = 0
        for e in s:
            if e in D:
                f = 1
                break
        if f == 0:
            print(s)
            exit(0)

if __name__ == '__main__':
    main()
# Original solution
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = list(map(int,input().split()))
    D = set(list(input().split()))
    for k in range(N,100001):
        s = str(k)
        f = 0
        for e in s:
            if e in D:
                f = 1
                break
        if f == 0:
            print(s)
            exit(0)

if __name__ == '__main__':
    main()


# Optimized solution
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = list(map(int,input().split()))
    D = set(input().split())
    for ans in range(N,1000000):
        f = 0
        for e in str(ans):
            if e in D:
                f = 1
                break
        if f == 0:
            print(ans)
            exit(0)
if __name__ == '__main__':
    main()
# Original solution
#n=int(input())
ans=10**6
n,k=list(map(int,input().split()))
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
        
for a in s+['0']:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    x=list(map(int,[a+b+c+d+e,b+c+d+e,c+d+e,d+e,e]))
                    for i in x:
                        if i>=n:
                            ans=min(i,ans)
print(ans)


# Optimized solution
n,k=list(map(int,input().split()))
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
    
for x in range(n,10*n):
    flg=True
    for d in str(x):
        if d not in s:
            flg=False
    if flg:
        print(x)
        break
# Original solution
N, K = list(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

# Optimized solution
N,K = list(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)
# Original solution
n,k=list(map(int,input().split()))
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+10**c
                t=1
                break
    if t==0:
        break
print(n)

# Optimized solution
n,k=list(map(int,input().split()))
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+1
                t=1
                break
    if t==0:
        break
print(n)
# Original solution
n,k=list(map(int,input().split()))
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+1
                t=1
                break
    if t==0:
        break
print(n)

# Optimized solution
n,k=list(map(int,input().split()))
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                r=10**(q-c-1)
                n=int(n/r+1)*r
                t=1
                break
    if t==0:
        break
print(n)
# Original solution
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,100*N):
    if use >= set(str(i)):
        print(i)
        break


# Optimized solution
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,88889):
    if use >= set(str(i)):
        print(i)
        break
# Original solution
import itertools
N,K = list(map(int,input().split()))
D = list(map(int,input().split()))
A = []
for i in range(10):
    if i not in D:
        A.append(i)
cmin = 100000
k = len(str(N))
for i in range(k,6):
    for x in itertools.product(A,repeat=i):
        cnt = 0
        for j in range(i):
            cnt += x[j]*10**(i-1-j)
        if cnt>=N:
            cmin = min(cmin,cnt)
print(cmin)

# Optimized solution
N,K = list(map(int,input().split()))
D = list(map(int,input().split()))
E = []
for i in range(10):
    if i not in D:
        E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
    if int(N[i]) not in E:
        ind = i
        break
if ind==len(N):
    print(N)
else:
    flag = 0
    x = ""
    for i in range(ind,-1,-1):
        n = int(N[i])
        for e in E:
            if e>n:
                x = N[:i]+str(e)+str(E[0])*(len(N)-i-1)
                flag = 1
                break
        if flag==1:break
    if flag==0:
        if E[0]>0:
            a = E[0]
        else:
            a = E[1]
        x = str(a)+str(E[0])*len(N)
    print(x)
# Original solution
def main():
 num = list(map(int,input().split()))
 bad = list(map(int,input().split()))

 while True :
  flg=0
  
  for i in range(0,len(str(num[0]))):
   stnum=str(num[0])
   if int(stnum[i]) in bad:
    flg=1
    break
   
  if flg==1:
   num[0]+=1
   continue
  else:
   break
  
 print((num[0]))

main()

# Optimized solution
def main():
 num = list(map(int,input().split()))
 bad = list(map(str,input().split()))

 while True :
  flg=0
  
  for i in range(0,len(str(num[0]))):
   stnum=str(num[0])
   if stnum[i] in bad:
    flg=1
    break
   
  if flg==1:
   num[0]+=1
   continue
  else:
   break
  
 print((num[0]))

main()
# Original solution
n, k=list(map(int, input().split()))
d = list(input().split())
i=n
while True:
    count = 0
    for j in range(k):
        if d[j] in str(i):
            count += 1
    if count == 0:
        print(i)
        break
    else:
        i += 1

# Optimized solution
n,k = list(map(int, input().split()))
d = list(input().split())
while True:
    c=0
    for i in range(k):
        if d[i] in str(n):
            c+=1
    if c==0:
        print(n)
        break
    else:
        n+=1
# Original solution
def abc042_c():
    price, len_hate_set = list(map(int, input().split()))
    hate_set = set([int(i) for i in input().split()])

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

        price += 1


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


# Optimized solution
def abc042_c():
    price, len_hate_set = list(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([int(x) in usable_set for x in [int(str(price)[i]) for i in range(len(str(price)))]]) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print((abc042_c()))
# Original solution
def no_dislike_number(num, D):
    for dislike in D:
        if dislike in num:
            return False
    return True

MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

# Optimized solution
def no_dislike_number(num, D):
    for digit in num:
        if digit in D:
            return False
    return True
    # for dislike in D:
    #     if dislike in num:
    #         return False
    # return True

MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1
# Original solution
# encoding: utf-8
N, K = list(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)))

# Optimized solution
# encoding: utf-8
N, K = list(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)))
# Original solution
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

ans = n
while (1):

    c = True
    b = n
    while (b != 0):
        b = b // 10
        d = b % 10

        if d in a:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)


# Optimized solution
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

ans = n
b = n
while (1):

    c = True
    b = n
    while (b != 0):
        d = b % 10
        b = b // 10

        if d in a:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)
# Original solution
n,k = list(map(int,input().split()))
dls = list(map(int,input().split()))
while 1:
    s = list(map(int,list(str(n))))
    for i in dls:
        if i in s:
            break
    else:
        print(n)
        exit()
    n += 1

# Optimized solution
n,k = list(map(int,input().split()))
dls = list(map(str,input().split()))
while 1:
    s = str(n)
    for i in dls:
        if i in s:
            break
    else:
        print(n)
        exit()
    n += 1
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
#from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    #que = deque(r[1:])
    que = r[1:]
else:
    #que = deque(r)
    que = r

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        que.append(new)
    if que[-1] >= 10**6:
        break
    i += 1

ind = bisect.bisect_left(que, N)
#print(que)
#print(ind)
print((que[ind]))

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
#from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    #que = deque(r[1:])
    que = r[:][1:]
else:
    #que = deque(r)
    que = r[:]

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    #if que[-1] >= 10**6:
        #break
    i += 1

#ind = bisect.bisect_left(que, N)
#print(que)
#print(ind)
#print(que[ind])
# Original solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for i in list(map(int, input().rstrip('\n').split())):
        d[i]
    for i in range(n, 10 ** 10):
        s = str(i)
        b = True
        for j in range(len(s)):
            if int(s[j]) in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()


# Optimized solution
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for v in list(map(int, input().rstrip('\n').split())):
        d[str(v)]
    for i in range(n, 10 ** 10):
        s = str(i)
        b = True
        for v in s:
            if v in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    solve()
# Original solution
N,K = list(map(int,input().split()))
D = set(input().split())

while len(set(str(N))&D)>0:
  N+=1

print(N)

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

for n in range(N,100000):
  if len(set(str(n))&D)==0:
    print(n)
    break
# Original solution
N,K = list(map(int,input().split()))
D = set(input().split())

for n in range(N,100000):
  if len(set(str(n))&D)==0:
    print(n)
    break

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

while len(set(str(N))&D):
  N+=1

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


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

# Optimized solution
def main():
    N, K = list(map(int, input().split()))
    D = list(input().split())
    
    for i in range(N,100000):
        a = str(i)
        flag = True
        for d in D:
            if d in a:
                flag = False
                break
        if flag:
            print(i)
            exit()



if __name__ == "__main__":
    main()
# Original solution
N, K = list(map(int, input().split()))
Dset = set(input().split())
while True:
    if Dset & set(str(N)) == set():
        print(N)
        break
    else:
        N += 1


# Optimized solution
def check(num, ng):
    for c in str(num):
        if int(c) in ng:
            return False
    return True
N, K = list(map(int, input().split()))
D = set(list(map(int, input().split())))
while True:
    if check(N, D):
        print(N)
        break
    else:
        N += 1
# Original solution
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens.sort()

    ans = N
    repeat = True
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
    return ans


def main(args):
    # N, K = 9999, 1
    # forbiddens = [9]
    N, K = list(map(int, input().split()))
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


# Optimized solution
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a
AC
"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens = set(forbiddens)
    ans = N
    repeat = True
    
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
                
    return ans


def main(args):
    # N, K = 9999, 1
    # forbiddens = [9]
    N, K = list(map(int, input().split()))
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
# Original solution
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))

def dfs(N, M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(N, M + [D[0]], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(N, M+[d], i+1, 0)
        elif d > N[i]:
            dfs(N, M+[d], i+1, 1)
            break
    if D[0] == 0:
        dfs(N, [D[1], D[0]], 1, 1)
    else:
        dfs(N, [D[0], D[0]], 1, 1)

dfs(N, [], 0, 0)


# Optimized solution
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))
d0 = D[0]

def dfs(M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(M+[d0], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(M+[d], i+1, 0)
        elif d > N[i]:
            dfs(M+[d], i+1, 1)
            break
    if d0:
        dfs([d0], 0, 1)
    else:
        dfs([D[1]], 0, 1)
dfs([], 0, 0)