#

# Written by NoKnowledgeGG @YlePhan

# ('ω')

#

#import math

#mod = 10**9+7

#import itertools

#import fractions

#import numpy as np

#mod = 10**4 + 7

"""def kiri(n,m):

  r_ = n / m

  if (r_ - (n // m)) > 0:

    return (n//m) + 1

  else:

    return (n//m)"""



""" n! mod m 階乗

mod = 1e9 + 7

N = 10000000

fac = [0] * N

def ini():

  fac[0] = 1 % mod

  for i in range(1,N):

    fac[i] = fac[i-1] * i % mod"""



"""mod = 1e9+7

N = 10000000

pw = [0] * N

def ini(c):

  pw[0] = 1 % mod

  for i in range(1,N):

    pw[i] = pw[i-1] * c % mod"""



"""

def YEILD():

  yield 'one'

  yield 'two'

  yield 'three'

generator = YEILD()

print(next(generator))

print(next(generator))

print(next(generator))

"""

"""def gcd_(a,b):

  if b == 0:#結局はc,0の最大公約数はcなのに

    return a

  return gcd_(a,a % b) # a = p * b + q"""

"""def extgcd(a,b,x,y):

  d = a

  if b!=0:

    d = extgcd(b,a%b,y,x)

    y -= (a//b) * x

    print(x,y)

  else:

    x = 1

    y = 0

  return d"""





def readInts():

  return list(map(int,input().split()))



def main():

  n,k = readInts()

  D = input().split()

  #print(D)

  #print(list(str(now)))

  #print(set(str(n)) & set(D))

  

  #print({'2','5'} & {'2'})

  while set(str(n)) & set(D):

    n += 1

  print(n)

  

if __name__ == '__main__':

  main()
#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

from math import gcd

from itertools import combinations,permutations,accumulate, product # (string,3) 3回

#from collections import deque

from collections import deque,defaultdict,Counter

import decimal

import re

import math

import bisect

import heapq

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#

# my_round_int = lambda x:np.round((x*2 + 1)//2)

# 四捨五入g

#

# インデックス系

# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);

# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);

#

#

import sys

sys.setrecursionlimit(10000000)

mod = 10**9 + 7

#mod = 9982443453

#mod = 998244353

INF = float('inf')

from sys import stdin

readline = stdin.readline

def readInts():

  return list(map(int,readline().split()))

def readTuples():

    return tuple(map(int,readline().split()))

def I():

    return int(readline())



#dic = defaultdict(int)

n,k = readInts()

D = Counter(readInts())

def ok(n):

    while n:

        v = n%10

        if D[v]:

            return False

        n //= 10

    return True

ans = n

for i in range(n, 100000):

    if ok(i):

        ans = i

        break

print(ans)

#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
# import math
# mod = 10**9+7
# import itertools
# import fractions
# import numpy as np
# mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""
"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""
"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
    return list(map(int, input().split()))


def main():
    n, k = readInts()
    D = input().split()
    # print(D)
    # print(list(str(now)))
    # print(set(str(n)) & set(D))
    # print({'2','5'} & {'2'})
    while set(str(n)) & set(D):
        n += 1
    print(n)


if __name__ == "__main__":
    main()

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations, permutations, accumulate, product  # (string,3) 3回

# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys

sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
# mod = 998244353
INF = float("inf")
from sys import stdin

readline = stdin.readline


def readInts():
    return list(map(int, readline().split()))


def readTuples():
    return tuple(map(int, readline().split()))


def I():
    return int(readline())


# dic = defaultdict(int)
n, k = readInts()
D = Counter(readInts())


def ok(n):
    while n:
        v = n % 10
        if D[v]:
            return False
        n //= 10
    return True


ans = n
for i in range(n, 100000):
    if ok(i):
        ans = i
        break
print(ans)

+# from statistics import median +# import collections +# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] +from math import gcd +from itertools import combinations, permutations, accumulate, product  # (string,3) 3回 + +# from collections import deque +from collections import deque, defaultdict, Counter +import decimal +import re +import math +import bisect +import heapq + -# Written by NoKnowledgeGG @YlePhan -# ('ω') -# import math -# mod = 10**9+7 -# import itertools -# import fractions -# import numpy as np -# mod = 10**4 + 7 -"""def kiri(n,m): -  r_ = n / m -  if (r_ - (n // m)) > 0: -    return (n//m) + 1 -  else: -    return (n//m)""" -""" n! mod m 階乗 -mod = 1e9 + 7 -N = 10000000 -fac = [0] * N -def ini(): -  fac[0] = 1 % mod -  for i in range(1,N): -    fac[i] = fac[i-1] * i % mod""" -"""mod = 1e9+7 -N = 10000000 -pw = [0] * N -def ini(c): -  pw[0] = 1 % mod -  for i in range(1,N): -    pw[i] = pw[i-1] * c % mod""" -""" -def YEILD(): -  yield 'one' -  yield 'two' -  yield 'three' -generator = YEILD() -print(next(generator)) -print(next(generator)) -print(next(generator)) -""" -"""def gcd_(a,b): -  if b == 0:#結局はc,0の最大公約数はcなのに -    return a -  return gcd_(a,a % b) # a = p * b + q""" -"""def extgcd(a,b,x,y): -  d = a -  if b!=0: -    d = extgcd(b,a%b,y,x) -    y -= (a//b) * x -    print(x,y) -  else: -    x = 1 -    y = 0 -  return d""" +# +# pythonで無理なときは、pypyでやると正解するかも！！ +# +# +# my_round_int = lambda x:np.round((x*2 + 1)//2) +# 四捨五入g +# +# インデックス系 +# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); +# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); +# +# +import sys + +sys.setrecursionlimit(10000000) +mod = 10**9 + 7 +# mod = 9982443453 +# mod = 998244353 +INF = float("inf") +from sys import stdin + +readline = stdin.readline -    return list(map(int, input().split())) +    return list(map(int, readline().split())) -def main(): -    n, k = readInts() -    D = input().split() -    # print(D) -    # print(list(str(now))) -    # print(set(str(n)) & set(D)) -    # print({'2','5'} & {'2'}) -    while set(str(n)) & set(D): -        n += 1 -    print(n) +def readTuples(): +    return tuple(map(int, readline().split())) -if __name__ == "__main__": -    main() +def I(): +    return int(readline()) + + +# dic = defaultdict(int) +n, k = readInts() +D = Counter(readInts()) + + +def ok(n): +    while n: +        v = n % 10 +        if D[v]: +            return False +        n //= 10 +    return True + + +ans = n +for i in range(n, 100000): +    if ok(i): +        ans = i +        break +print(ans)