import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST
main=B.interact$B.pack.show.f.unfoldr (B.readInt.B.dropWhile isSpace)
f (_:c:stcs)=runST $ do
    ar<-newArray ((0,0),(c,100001)) 0::ST s (STUArray s (Int,Int) Int)
    forM_ (pack stcs) $ \(s,t,c) -> do
        writeArray ar (c,s) =<< succ <$> readArray ar (c,s)
        writeArray ar (c,t+1) =<< pred <$> readArray ar (c,t+1)
    forM_ [(i,t)|i<-[1..c],t<-[1..100000]] $ \(i,t)->
        writeArray ar (i,t) =<< (+) <$> readArray ar (i,t-1) <*> readArray ar (i,t)
    forM_ [(i,t)|i<-[1..c],t<-[1..100000]] $ \(i,t)-> do
        u<-readArray ar (i,t)
        when (u/=0) $ writeArray ar (0,t) =<< succ <$> readArray ar (0,t)
    maximum <$> forM [1..100000] (\t->readArray ar (0,t))
    where
        pack [] = []
        pack (s:t:c:r) = (s,t,c):pack r