public static void main ( String args [ ] ) {
  Scanner d = new Scanner ( System . in ) ;
  int n , x , i , z ;
  n = d . nextInt ( ) ;
  x = d . nextInt ( ) ;
  int a [ ] = new int [ n ] ;
  Set < Integer > s = new HashSet < > ( ) ;
  Set < Integer > s1 = new HashSet < > ( ) ;
  for ( i = 0 ;
  i < n ;
  i ++ ) a [ i ] = d . nextInt ( ) ;
  z = - 1 ;
  for ( i = 0 ;
  i < n ;
  i ++ ) {
    if ( s . isEmpty ( ) ) {
      s . add ( a [ i ] ) ;
      s1 . add ( a [ i ] & x ) ;
    }
    else if ( s . contains ( a [ i ] ) ) {
      z = 0 ;
    }
    else if ( s . contains ( a [ i ] & x ) || s1 . contains ( a [ i ] ) ) {
      if ( z != 0 ) {
        z = 1 ;
        s . add ( a [ i ] ) ;
      }
    }
    else {
      s . add ( a [ i ] ) ;
      s1 . add ( a [ i ] & x ) ;
    }
  }
  if ( s1 . size ( ) < s . size ( ) && z == - 1 ) System . out . println ( 2 ) ;
  else System . out . println ( z ) ;
}

public static void main ( String args [ ] ) { Scanner d = new Scanner ( System . in ) ; int n , x , i , z ; n = d . nextInt ( ) ; x = d . nextInt ( ) ; int a [ ] = new int [ n ] ; Set < Integer > s = new HashSet < > ( ) ; Set < Integer > s1 = new HashSet < > ( ) ; for ( i = 0 ; i < n ; i ++ ) a [ i ] = d . nextInt ( ) ; z = - 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( s . isEmpty ( ) ) { s . add ( a [ i ] ) ; s1 . add ( a [ i ] & x ) ; } else if ( s . contains ( a [ i ] ) ) { z = 0 ; } else if ( s . contains ( a [ i ] & x ) || s1 . contains ( a [ i ] ) ) { if ( z != 0 ) { z = 1 ; s . add ( a [ i ] ) ; } } else { s . add ( a [ i ] ) ; s1 . add ( a [ i ] & x ) ; } } if ( s1 . size ( ) < s . size ( ) && z == - 1 ) System . out . println ( 2 ) ; else System . out . println ( z ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) 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)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (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 (identifier))))) (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)) 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)) arguments: (argument_list)))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (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 (array_access array: (identifier) index: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))))) alternative: (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))))))