let () =
  let n, c = Scanf.scanf "%d %d\n" (fun n c -> n, c) in
  let cs = Array.make c []
  in
  for i = 0 to n - 1 do
    Scanf.scanf "%d %d %d\n" (fun s t c ->
      cs.(c - 1) <- (s, t) :: cs.(c - 1))
  done;
  let channels = Array.make 200003 0 in
  begin Array.map (fun sts ->
    match List.sort compare sts with
    | [] -> []
    | (s, t) :: sts ->
        List.fold_left (fun (s, t, acc) (s', t') ->
          if t = s' then (s, t', acc)
          else (s', t', (s, t) :: acc)) (s, t, []) sts
        |> (fun (s, t, acc) -> (s, t) :: acc)) cs
  |> Array.to_list
  |> List.concat
  |> List.iter (fun (s, t) ->
      channels.(2 * s - 1) <- channels.(2 * s - 1) + 1;
      channels.(2 * t) <- channels.(2 * t) - 1)
  end;
  for i = 1 to Array.length channels - 1 do
    channels.(i) <- channels.(i) + channels.(i - 1)
  done;
  Printf.printf "%d\n" (Array.fold_left max 0 channels)