import qualified Data.Set as S

---
readInt :: String -> Int
readInt = read

remove :: Eq a => a -> [a] -> [a]
remove e = filter (/= e)

---
main :: IO ()
main = do
    [price, _] <- fmap (map readInt . words) getLine
    hDigits    <- fmap (S.fromList . remove ' ') getLine
    
    print $ head [
        p | p <- [1..], 
        S.null $ S.intersection hDigits (S.fromList . show $ p),
        price <= p
        ]
