public static void main ( String [ ] args ) {
  try ( Scanner sc = new Scanner ( System . in ) ) {
    String [ ] nm = sc . nextLine ( ) . split ( " " ) ;
    int n = Integer . parseInt ( nm [ 0 ] ) ;
    long k = Long . parseLong ( nm [ 1 ] ) ;
    String [ ] alist = sc . nextLine ( ) . split ( " " ) ;
    long [ ] aary = new long [ n ] ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      aary [ i ] = Long . parseLong ( alist [ i ] ) ;
    }
    String [ ] bsary = new String [ n ] ;
    int maxbslen = 0 ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      bsary [ i ] = Long . toBinaryString ( aary [ i ] ) ;
      maxbslen = Math . max ( maxbslen , bsary [ i ] . length ( ) ) ;
    }
    long bitcount [ ] = new long [ maxbslen ] ;
    for ( String bs : bsary ) {
      for ( int j = bs . length ( ) - 1 ;
      j >= 0 ;
      j -- ) {
        if ( bs . charAt ( j ) == '1' ) {
          bitcount [ bs . length ( ) - 1 - j ] ++ ;
        }
      }
    }
    int xdigit = Long . toBinaryString ( k ) . length ( ) ;
    long x = 0 ;
    for ( int i = xdigit - 1 ;
    i >= 0 ;
    i -- ) {
      long next = x + ( long ) Math . pow ( 2 , i ) ;
      if ( next <= k ) {
        if ( i >= bitcount . length ) {
          x = next ;
        }
        else {
          if ( bitcount [ i ] <= n / 2 ) {
            x = next ;
          }
        }
      }
    }
    long f = 0 ;
    for ( long a : aary ) {
      f += x ^ a ;
    }
    System . out . println ( f ) ;
  }
}

public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { String [ ] nm = sc . nextLine ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( nm [ 0 ] ) ; long k = Long . parseLong ( nm [ 1 ] ) ; String [ ] alist = sc . nextLine ( ) . split ( " ▁ " ) ; long [ ] aary = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { aary [ i ] = Long . parseLong ( alist [ i ] ) ; } String [ ] bsary = new String [ n ] ; int maxbslen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bsary [ i ] = Long . toBinaryString ( aary [ i ] ) ; maxbslen = Math . max ( maxbslen , bsary [ i ] . length ( ) ) ; } long bitcount [ ] = new long [ maxbslen ] ; for ( String bs : bsary ) { for ( int j = bs . length ( ) - 1 ; j >= 0 ; j -- ) { if ( bs . charAt ( j ) == '1' ) { bitcount [ bs . length ( ) - 1 - j ] ++ ; } } } int xdigit = Long . toBinaryString ( k ) . length ( ) ; long x = 0 ; for ( int i = xdigit - 1 ; i >= 0 ; i -- ) { long next = x + ( long ) Math . pow ( 2 , i ) ; if ( next <= k ) { if ( i >= bitcount . length ) { x = next ; } else { if ( bitcount [ i ] <= n / 2 ) { x = next ; } } } } long f = 0 ; for ( long a : aary ) { f += x ^ a ; } System . out . println ( f ) ; } }
(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 (try_with_resources_statement resources: (resource_specification (resource type: (type_identifier) name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) body: (block (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (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: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (identifier))))) (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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (array_access array: (identifier) index: (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))))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) right: (identifier))))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))))