import Data.List.Split
main = mapM_ (print . solve . map (map read . words)) . chunksOf 2 . lines =<< getContents
solve [[n,k],ds] = head $ filter (null . filter (flip elem ds) . f) [n..]
f 0 = []
f i = i`mod`10:f (i`div`10)