public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int N = sc . nextInt ( ) ;
  int C = sc . nextInt ( ) ;
  final int nMax = 100000 ;
  LinkedList < int [ ] > [ ] dic = new LinkedList [ C + 1 ] ;
  for ( int i = 0 ;
  i <= C ;
  i ++ ) dic [ i ] = new LinkedList < > ( ) ;
  for ( int i = 1 ;
  i <= N ;
  i ++ ) {
    int s = sc . nextInt ( ) ;
    int t = sc . nextInt ( ) ;
    int c = sc . nextInt ( ) ;
    dic [ c ] . add ( new int [ ] {
      s , t }
      ) ;
    }
    int [ ] res = new int [ nMax + 5 ] ;
    for ( int i = 1 ;
    i <= C ;
    i ++ ) {
      if ( dic [ i ] . size ( ) == 0 ) continue ;
      int [ ] cur = new int [ nMax + 5 ] ;
      while ( dic [ i ] . size ( ) > 0 ) {
        int [ ] temp = dic [ i ] . remove ( ) ;
        cur [ temp [ 0 ] ] ++ ;
        cur [ temp [ 1 ] + 1 ] -- ;
      }
      for ( int j = 1 ;
      j < nMax + 5 ;
      j ++ ) cur [ j ] = cur [ j - 1 ] + cur [ j ] ;
      for ( int j = 1 ;
      j < nMax + 5 ;
      j ++ ) {
        if ( cur [ j ] > 0 ) res [ j ] ++ ;
      }
    }
    int ans = 0 ;
    for ( int j = 1 ;
    j < nMax + 5 ;
    j ++ ) ans = Math . max ( ans , res [ j ] ) ;
    System . out . println ( ans ) ;
  }
  
public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; final int nMax = 100000 ; LinkedList < int [ ] > [ ] dic = new LinkedList [ C + 1 ] ; for ( int i = 0 ; i <= C ; i ++ ) dic [ i ] = new LinkedList < > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; dic [ c ] . add ( new int [ ] { s , t } ) ; } int [ ] res = new int [ nMax + 5 ] ; for ( int i = 1 ; i <= C ; i ++ ) { if ( dic [ i ] . size ( ) == 0 ) continue ; int [ ] cur = new int [ nMax + 5 ] ; while ( dic [ i ] . size ( ) > 0 ) { int [ ] temp = dic [ i ] . remove ( ) ; cur [ temp [ 0 ] ] ++ ; cur [ temp [ 1 ] + 1 ] -- ; } for ( int j = 1 ; j < nMax + 5 ; j ++ ) cur [ j ] = cur [ j - 1 ] + cur [ j ] ; for ( int j = 1 ; j < nMax + 5 ; j ++ ) { if ( cur [ j ] > 0 ) res [ j ] ++ ; } } int ans = 0 ; for ( int j = 1 ; j < nMax + 5 ; j ++ ) ans = Math . max ( ans , res [ j ] ) ; System . out . println ( ans ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (array_type element: (generic_type (type_identifier) (type_arguments (array_type element: (integral_type) dimensions: (dimensions)))) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (array_creation_expression type: (integral_type) dimensions: (dimensions) value: (array_initializer (identifier) (identifier)))))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (continue_statement)) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)))) (expression_statement (update_expression (array_access array: (identifier) index: (array_access array: (identifier) index: (decimal_integer_literal))))) (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (array_access array: (identifier) index: (identifier))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (array_access array: (identifier) index: (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))