let () =
  Scanf.scanf "%d %d" @@ fun n c ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d %d %d" (fun x y z -> x, y, z)) in
  Array.sort compare a;

  let pop t c = List.filter (fun (t',c') -> t < t' || (t' = t && c <> c')) in

  Array.fold_left (fun (z,q) (s,t,c) ->
    let q' = (t, c) :: pop s c q in
    (max z (List.length q'), q')) (0, []) a
  |> fst |> Printf.printf "%d\n"