import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  [n, m, x] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    tests = sequence . replicate n $ [False, True] :: [[Bool]]
  cas <- sequence . replicate n $ map unsafeTextToInt . T.words <$> T.getLine :: IO [[Int]]
  let
    cs = map head . filter (all (x <=) . tail) . map (foldl (zipWith (+)) (replicate (succ m) 0) . map fst . filter snd . zip cas) $ tests :: [Int]
  print $ if null cs then (-1) else minimum cs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
