import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, c] <- getInts
  ss <- replicateM n $ do
    [s, t, c] <- getInts
    return ((s, t), c)
  print $ solve ss

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve xs = maximum $ go (f xs) []
  where
    f = map fst . sort
      . concatMap (cnct . sort) 
      . groupBy (\(_, c1) (_, c2) -> c1 == c2)
      . sortBy (\(_, c1) (_, c2) -> compare c1 c2)
      where
        cnct [] = []
        cnct [x] = [x]
        cnct (x:y:zs) =
          case (x, y) of
            (((s1, t1), c), ((s2, t2), _))
              | t1 == s2 -> ((s1, t2), c) : cnct zs
            _ -> x : cnct (y:zs)
    go [] _ = []
    go (l@(s, t):ls) qs =
      let qs' = l : filter (\(s', t') ->
                              fromIntegral t' > fromIntegral s  - 0.5) qs in
      length qs' : go ls qs'
