-- ABD042 C - こだわり者いろはちゃん / Iroha's Obsession

import Control.Monad
import Data.List

main :: IO()
main = do
    [n,k] <- map read . words <$> getLine
    tabooLs <- map read . words <$> getLine
    print $ payVal n tabooLs
    


barabara :: Int -> [Int]
--数字をばらばらにする。1230は[1,2,3,0]になる。
barabara num
    | num < 10				= [num]
    | otherwise				= (barabara (div num 10)) ++ [(mod num 10)]

payVal :: Int -> [Int] -> Int
payVal num tabooLs
    | intersect (barabara num) tabooLs == []	= num
    | otherwise									= payVal (succ num) tabooLs
