import Data.List
import Data.Char
main=do
    [n,k]<-map read.words<$>getLine::IO[Int]
    ds<-map read.words<$>getLine::IO[Int]
    print.head $ dropWhile (chk ds) [n..]

chk ds n = any (flip elem ds.digitToInt) $ show n