public static void main ( String [ ] args ) throws IOException {
  input = br . readLine ( ) . split ( " " ) ;
  n = Integer . parseInt ( input [ 0 ] ) ;
  m = Integer . parseInt ( input [ 1 ] ) ;
  for ( int i = 0 ;
  i < n ;
  ++ i ) {
    g [ i ] = br . readLine ( ) . toCharArray ( ) ;
  }
  char t = ' ' ;
  boolean flag = true ;
  for ( int i = 0 ;
  i < n ;
  ++ i ) {
    if ( i != 0 && t == g [ i ] [ 0 ] ) {
      flag = false ;
      break ;
    }
    t = g [ i ] [ 0 ] ;
    for ( int j = 1 ;
    j < m ;
    ++ j ) {
      if ( t != g [ i ] [ j ] ) {
        flag = false ;
        break ;
      }
    }
    if ( ! flag ) {
      break ;
    }
  }
  bw . write ( flag ? "YES" : "NO" ) ;
  bw . close ( ) ;
}

public static void main ( String [ ] args ) throws IOException { input = br . readLine ( ) . split ( " ▁ " ) ; n = Integer . parseInt ( input [ 0 ] ) ; m = Integer . parseInt ( input [ 1 ] ) ; for ( int i = 0 ; i < n ; ++ i ) { g [ i ] = br . readLine ( ) . toCharArray ( ) ; } char t = ' ▁ ' ; boolean flag = true ; for ( int i = 0 ; i < n ; ++ i ) { if ( i != 0 && t == g [ i ] [ 0 ] ) { flag = false ; break ; } t = g [ i ] [ 0 ] ; for ( int j = 1 ; j < m ; ++ j ) { if ( t != g [ i ] [ j ] ) { flag = false ; break ; } } if ( ! flag ) { break ; } } bw . write ( flag ? " YES " : " NO " ) ; bw . close ( ) ; }
(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 (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (character_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (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: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (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: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement))))) (if_statement condition: (parenthesized_expression (unary_expression operand: (identifier))) consequence: (block (break_statement))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (ternary_expression condition: (identifier) consequence: (string_literal) alternative: (string_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))