import Control.Applicative

getDigits :: Int -> [Int]
getDigits n | n < 10 = [n]
            | otherwise = (n `mod` 10) : (getDigits (n `div` 10))

getBigger :: Int -> [Int] -> Int
getBigger n bads | n `elem` bads = getBigger ((n+1) `mod` 10) bads
                 | otherwise = n

solve :: [Int] -> [Int] -> ([Int],Bool)
solve [] _ = ([],False)
solve (x:xs) bads | x `elem` bads = (nextN:(take (length xs) [small,small..]),nextN<x)
                  | otherwise = case b of
                                    False -> (x:a,False)
                                    True -> (nextN:a,nextN<=x)
                where nextN = getBigger ((x+1) `mod` 10) bads
                      (a,b) = solve xs bads
                      small = head $ filter (\x -> not (x`elem` bads)) [0..9]

solve' :: [Int] -> [Int] -> [Int]
solve' xs bads | b = (head $ filter (\x -> not (x `elem` bads)) [1..9]):a
               | otherwise = a
             where (a,b) = solve xs bads

main :: IO ()
main = do
    [n,k] <- map read . words <$> getLine
    bads <- map read . words <$> getLine
    mapM_ (\x -> putStr . show $ x) $ solve' (reverse . getDigits $ n) bads
    putStrLn ""
