public static void main ( String [ ] args ) throws IOException {
  BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  reader . readLine ( ) ;
  List < Integer > counts = Stream . of ( reader . readLine ( ) . trim ( ) . split ( " " ) ) . map ( Integer :: parseInt ) . sorted ( ) . collect ( Collectors . toList ( ) ) ;
  if ( counts . size ( ) == 1 ) {
    System . out . println ( "0" ) ;
    return ;
  }
  int result = 0 ;
  for ( int i = 0 ;
  i < counts . size ( ) - 2 ;
  i ++ ) {
    if ( counts . get ( i ) == 0 ) continue ;
    if ( counts . get ( i ) . equals ( counts . get ( i + 1 ) ) ) {
      if ( counts . get ( i ) . equals ( counts . get ( i + 2 ) ) ) {
        System . out . println ( "-1" ) ;
        return ;
      }
      ++ i ;
      ++ result ;
    }
  }
  if ( counts . get ( counts . size ( ) - 1 ) . equals ( counts . get ( counts . size ( ) - 2 ) ) && ! counts . get ( counts . size ( ) - 1 ) . equals ( 0 ) ) ++ result ;
  System . out . println ( result ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; reader . readLine ( ) ; List < Integer > counts = Stream . of ( reader . readLine ( ) . trim ( ) . split ( " ▁ " ) ) . map ( Integer :: parseInt ) . sorted ( ) . collect ( Collectors . toList ( ) ) ; if ( counts . size ( ) == 1 ) { System . out . println ( "0" ) ; return ; } int result = 0 ; for ( int i = 0 ; i < counts . size ( ) - 2 ; i ++ ) { if ( counts . get ( i ) == 0 ) continue ; if ( counts . get ( i ) . equals ( counts . get ( i + 1 ) ) ) { if ( counts . get ( i ) . equals ( counts . get ( i + 2 ) ) ) { System . out . println ( " - 1" ) ; return ; } ++ i ; ++ result ; } } if ( counts . get ( counts . size ( ) - 1 ) . equals ( counts . get ( counts . size ( ) - 2 ) ) && ! counts . get ( counts . size ( ) - 1 ) . equals ( 0 ) ) ++ result ; System . out . println ( result ) ; }
(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)))))))) (expression_statement (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: (method_invocation object: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) name: (identifier) arguments: (argument_list (method_reference (identifier) (identifier)))) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal))) consequence: (continue_statement)) (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))))) consequence: (block (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (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)))) name: (identifier) arguments: (argument_list (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: (unary_expression operand: (method_invocation object: (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)))) name: (identifier) arguments: (argument_list (decimal_integer_literal)))))) consequence: (expression_statement (update_expression (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))