public static void main ( String [ ] args ) throws IOException {
  BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  PrintWriter pw = new PrintWriter ( System . out ) ;
  int t = 1 ;
  while ( t -- > 0 ) {
    int n = Integer . parseInt ( br . readLine ( ) ) ;
    long dp [ ] [ ] = new long [ 26 ] [ 26 ] ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      String x = br . readLine ( ) . trim ( ) ;
      int a = x . charAt ( 0 ) - 'a' ;
      int b = x . charAt ( x . length ( ) - 1 ) - 'a' ;
      for ( int j = 0 ;
      j < 26 ;
      j ++ ) {
        if ( dp [ j ] [ a ] == 0 ) continue ;
        dp [ j ] [ b ] = Math . max ( dp [ j ] [ b ] , dp [ j ] [ a ] + x . length ( ) ) ;
      }
      dp [ a ] [ b ] = Math . max ( dp [ a ] [ b ] , x . length ( ) ) ;
    }
    long ans = 0 ;
    for ( int i = 0 ;
    i < 26 ;
    i ++ ) {
      ans = Math . max ( ans , dp [ i ] [ i ] ) ;
    }
    pw . println ( ans ) ;
  }
  pw . flush ( ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int t = 1 ; while ( t -- > 0 ) { int n = Integer . parseInt ( br . readLine ( ) ) ; long dp [ ] [ ] = new long [ 26 ] [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { String x = br . readLine ( ) . trim ( ) ; int a = x . charAt ( 0 ) - ' a ' ; int b = x . charAt ( x . length ( ) - 1 ) - ' a ' ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( dp [ j ] [ a ] == 0 ) continue ; dp [ j ] [ b ] = Math . max ( dp [ j ] [ b ] , dp [ j ] [ a ] + x . length ( ) ) ; } dp [ a ] [ b ] = Math . max ( dp [ a ] [ b ] , x . length ( ) ) ; } long ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { ans = Math . max ( ans , dp [ i ] [ i ] ) ; } pw . println ( ans ) ; } pw . flush ( ) ; }
(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 (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) (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: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) 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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal)) dimensions: (dimensions_expr (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (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: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) right: (character_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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))) consequence: (continue_statement)) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))