import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,c] <- getIntList
    st <- replicateM n $ do
        [s,t,c] <- getIntList
        return (c,(s-1,t))
    let st' = f $ sort st
            where f [] = []
                  f (x:[]) = (x:[])
                  f ((c1,(s1,t1)) : (c2,(s2,t2)) : xs)
                      | c1 == c2 && t1 == s2+1 = f ((c1,(s1,t2)) : xs)
                      | otherwise = (c1,(s1,t1)) : f ((c2,(s2,t2)) : xs)
    let result = VU.create $ do
            vec <- VUM.replicate 100002 (0 :: Int)
            forM_ st' $ \(_,(s,t)) -> do
                VUM.modify vec succ s
                VUM.modify vec pred t
            return vec
    let ans = VU.maximum $ VU.scanl (+) 0 result
    print ans