import qualified Data.Set as S

main :: IO ()
main = do
    [n, _] <- map read . words <$> getLine :: IO [Int]
    ds <- map read . words <$> getLine :: IO [Int]
    print $ head [i|i<-[n..], all (`S.notMember` S.fromList (digits i)) ds]

digits :: Int -> [Int]
digits 0 = []
digits n = mod n 10 : digits (div n 10)