import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time



sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7



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

def I(): return int(eval(input()))

def LS(): return input().split()

def S(): return eval(input())



def main():

  n,k=LI()

  

  l=LI()



  a=0

  while True:

    a+=1

    if a>=n:

      f=True

      for x in list(str(a)):

        if int(x) in l:

          f=False

          break

      if f:

        return a



print((main()))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time



sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7



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

def I(): return int(eval(input()))

def LS(): return input().split()

def S(): return eval(input())



def main():

  n,k=LI()

  l=LS()



  ans=1

  while True:

    if ans>=n:

      s=str(ans)



      f=True

      for x in s:

        if x in l:

          f=False

          break



      if f:

        return ans



    ans+=1



print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


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


def I():
    return int(eval(input()))


def LS():
    return input().split()


def S():
    return eval(input())


def main():
    n, k = LI()
    l = LI()
    a = 0
    while True:
        a += 1
        if a >= n:
            f = True
            for x in list(str(a)):
                if int(x) in l:
                    f = False
                    break
            if f:
                return a


print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


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


def I():
    return int(eval(input()))


def LS():
    return input().split()


def S():
    return eval(input())


def main():
    n, k = LI()
    l = LS()
    ans = 1
    while True:
        if ans >= n:
            s = str(ans)
            f = True
            for x in s:
                if x in l:
                    f = False
                    break
            if f:
                return ans
        ans += 1


print((main()))

-    l = LI() -    a = 0 +    l = LS() +    ans = 1 -        a += 1 -        if a >= n: +        if ans >= n: +            s = str(ans) -            for x in list(str(a)): -                if int(x) in l: +            for x in s: +                if x in l: -                return a +                return ans +        ans += 1