public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int N = sc . nextInt ( ) ;
  String S = sc . next ( ) ;
  if ( N == 1 ) {
    if ( S . equals ( "b" ) ) {
      System . out . println ( 0 ) ;
      return ;
    }
    else {
      System . out . println ( - 1 ) ;
      return ;
    }
  }
  for ( int i = 0 ;
  i < S . length ( ) ;
  i ++ ) {
    if ( S . charAt ( i ) == 'a' || S . charAt ( i ) == 'b' || S . charAt ( i ) == 'c' ) {
    }
    else {
      System . out . println ( - 1 ) ;
      return ;
    }
  }
  StringBuilder sb = new StringBuilder ( ) ;
  sb . append ( "b" ) ;
  for ( int i = 1 ;
  i <= 100 ;
  i ++ ) {
    if ( i % 3 == 1 ) {
      sb . insert ( 0 , "a" ) ;
      sb . append ( "c" ) ;
    }
    else if ( i % 3 == 2 ) {
      sb . insert ( 0 , "c" ) ;
      sb . append ( "a" ) ;
    }
    else if ( i % 3 == 0 ) {
      sb . insert ( 0 , "b" ) ;
      sb . append ( "b" ) ;
    }
    String str = sb . toString ( ) ;
    if ( str . length ( ) == N && str . equals ( S ) ) {
      System . out . println ( i ) ;
      return ;
    }
    else if ( str . length ( ) == N && ! str . equals ( S ) ) {
      System . out . println ( - 1 ) ;
      return ;
    }
    else if ( str . length ( ) > N ) {
      System . out . println ( - 1 ) ;
      return ;
    }
  }
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; if ( N == 1 ) { if ( S . equals ( " b " ) ) { System . out . println ( 0 ) ; return ; } else { System . out . println ( - 1 ) ; return ; } } for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == ' a ' || S . charAt ( i ) == ' b ' || S . charAt ( i ) == ' c ' ) { } else { System . out . println ( - 1 ) ; return ; } } StringBuilder sb = new StringBuilder ( ) ; sb . append ( " b " ) ; for ( int i = 1 ; i <= 100 ; i ++ ) { if ( i % 3 == 1 ) { sb . insert ( 0 , " a " ) ; sb . append ( " c " ) ; } else if ( i % 3 == 2 ) { sb . insert ( 0 , " c " ) ; sb . append ( " a " ) ; } else if ( i % 3 == 0 ) { sb . insert ( 0 , " b " ) ; sb . append ( " b " ) ; } String str = sb . toString ( ) ; if ( str . length ( ) == N && str . equals ( S ) ) { System . out . println ( i ) ; return ; } else if ( str . length ( ) == N && ! str . equals ( S ) ) { System . out . println ( - 1 ) ; return ; } else if ( str . length ( ) > N ) { System . out . println ( - 1 ) ; return ; } } }
(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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (return_statement)) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) (return_statement))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)))) consequence: (block) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) (return_statement))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_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: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (string_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (string_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (string_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (return_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier)) right: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) (return_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) (return_statement)))))))))