import Data.String( fromString)
main = do
    [n,k] <- return . map (read::String->Int) . words =<< getLine
    ds <- return . words =<< getLine
    let	p nm = and $ map (\s->(head s)`notElem` show nm) ds
    print $ head $ filter p [n..]
