public static void main ( String [ ] args ) throws Exception {
  Scanner sc = new Scanner ( System . in ) ;
  int n = sc . nextInt ( ) ;
  int l = sc . nextInt ( ) ;
  ArrayDeque < Integer > rq = new ArrayDeque < Integer > ( ) ;
  ArrayDeque < Integer > lq = new ArrayDeque < Integer > ( ) ;
  long ans = 0 ;
  long sumi_cnt = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int x = sc . nextInt ( ) ;
    char direction = sc . next ( ) . charAt ( 0 ) ;
    if ( direction == 'L' ) {
      if ( rq . isEmpty ( ) ) {
        long cnt = x - 1 - sumi_cnt ;
        ans += cnt ;
        sumi_cnt ++ ;
      }
      else {
        lq . addLast ( x ) ;
      }
    }
    else {
      if ( lq . isEmpty ( ) ) {
        rq . addLast ( x ) ;
      }
      else {
        long cnt = calc ( rq , lq ) ;
        ans += cnt ;
        rq . push ( x ) ;
      }
    }
  }
  if ( lq . isEmpty ( ) ) {
    sumi_cnt = 0 ;
    while ( rq . size ( ) > 0 ) {
      int x = rq . pollLast ( ) ;
      long cnt = l - x - sumi_cnt ;
      ans += cnt ;
      sumi_cnt ++ ;
    }
  }
  else {
    ans += calc ( rq , lq ) ;
  }
  System . out . println ( ans ) ;
}

public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; ArrayDeque < Integer > rq = new ArrayDeque < Integer > ( ) ; ArrayDeque < Integer > lq = new ArrayDeque < Integer > ( ) ; long ans = 0 ; long sumi_cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; char direction = sc . next ( ) . charAt ( 0 ) ; if ( direction == ' L ' ) { if ( rq . isEmpty ( ) ) { long cnt = x - 1 - sumi_cnt ; ans += cnt ; sumi_cnt ++ ; } else { lq . addLast ( x ) ; } } else { if ( lq . isEmpty ( ) ) { rq . addLast ( x ) ; } else { long cnt = calc ( rq , lq ) ; ans += cnt ; rq . push ( x ) ; } } } if ( lq . isEmpty ( ) ) { sumi_cnt = 0 ; while ( rq . size ( ) > 0 ) { int x = rq . pollLast ( ) ; long cnt = l - x - sumi_cnt ; ans += cnt ; sumi_cnt ++ ; } } else { ans += calc ( rq , lq ) ; } 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))) (throws (type_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 type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) alternative: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) 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: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier)))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))