import Data.Maybe
import Data.List

main = interact $ unlines . map (show' . whenCanWeMeet) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nq:xs) = (q, map (map read . tail . words) dates) : read' xs'
   where
    [n,q] = (map read . words) nq
    (dates,xs') = splitAt n xs
  show' = maybe "0" show

whenCanWeMeet :: (Int, [[Int]]) -> Maybe Int
whenCanWeMeet (q,dates) = fmap head $ listToMaybe $ sort $ filter ((== max_attend) . length) ands
 where
  ands = filter ((>= q) . length) $ group $ sort $ concat dates
  max_attend = maximum (map length ands)