import Data.List

main :: IO ()
main = do
  [n, _] <- words <$> getLine
  d <- concat . words <$> getLine
  let
    like = "0123456789" \\ d
  putStrLn $ solve n like

solve :: String -> String -> String
solve [] _ = []
solve (x:xs) d = if x `elem` d
  then x : solve xs d
  else let po = filter (>= x) d in
    if null po then replicate (length xs+2) (minimum (d\\"0")) else minimum po : replicate (length xs) (minimum d)
