import qualified Control.Monad.ST as S
import qualified Data.Array.ST as S
import qualified Data.Array as S
import qualified Data.STRef as S
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.List
import Data.Maybe

main :: IO ()
main = do
    [n,_] <- map read . words <$> getLine :: IO [Int]
    ns    <- replicateM n ((\[a,b,c]->(a,b,c)) . map (fst . fromJust . B.readInt) . 
                        B.words <$> B.getLine) :: IO [(Int,Int,Int)]


    let x  = 100000
        ms = {-# SCC "ms" #-} map (concatMap (\(a, b, _) -> [(a,1), (b,-1)]))
           $ groupBy (\(_, _, a) (_, _, b) -> a == b) ns :: [[(Int,Int)]]
        
        ls = {-# SCC "ls" #-} map (\l -> scanl (+) 0 . f 0 $ S.runST (do
            arr <- {-# SCC "alloc" #-} S.newArray (1, 100010) 0 :: S.ST s (S.STUArray s Int Int)
            {-# SCC "write" #-} forM_ l (\(i, a) -> S.writeArray arr i a)
            {-# SCC "freeze" #-} S.elems <$> S.freeze arr
            )) ms :: [[Int]]

    print . maximum . foldr (zipWith (+)) (head ls) $ tail ls

f :: Int -> [Int] -> [Int]
f n [] = [n]
f n (m:ms)
    | m < 0     = n : f m ms
    | otherwise = n+m : f 0 ms
