#include <algorithm>
#include <bits/stdc++.h>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <vector>

// lib/floor_log2.hpp
#ifndef FLOOR_LOG2_HPP
#define FLOOR_LOG2_HPP


namespace tools {
  std::uint32_t floor_log2(std::uint32_t x);
  std::uint64_t floor_log2(std::uint64_t x);
}

#endif

// lib/bitcount.hpp
#ifndef BITCOUNT_HPP
#define BITCOUNT_HPP


namespace tools {
  std::uint32_t bitcount(std::uint32_t x);
  std::uint64_t bitcount(std::uint64_t x);
}

#endif

// lib/pow2.hpp
#ifndef POW2_HPP
#define POW2_HPP

/*
usage:

tools::pow2(5) => 32
*/


namespace tools {
  template <typename T, typename std::enable_if<std::is_unsigned<T>::value, std::nullptr_t>::type = nullptr>
  constexpr T pow2(const T x) {
    return static_cast<T>(1) << x;
  }

  template <typename T, typename std::enable_if<std::is_signed<T>::value, std::nullptr_t>::type = nullptr>
  constexpr T pow2(const T x) {
    return static_cast<T>(static_cast<typename std::make_unsigned<T>::type>(1) << static_cast<typename std::make_unsigned<T>::type>(x));
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/floor_log2.cpp

namespace tools {
  std::uint32_t floor_log2(std::uint32_t x) {
    x |= (x >> static_cast<std::uint32_t>(1));
    x |= (x >> static_cast<std::uint32_t>(2));
    x |= (x >> static_cast<std::uint32_t>(4));
    x |= (x >> static_cast<std::uint32_t>(8));
    x |= (x >> static_cast<std::uint32_t>(16));
    return bitcount(x) - static_cast<std::uint32_t>(1);
  }

  std::uint64_t floor_log2(std::uint64_t x) {
    x |= (x >> static_cast<std::uint64_t>(1));
    x |= (x >> static_cast<std::uint64_t>(2));
    x |= (x >> static_cast<std::uint64_t>(4));
    x |= (x >> static_cast<std::uint64_t>(8));
    x |= (x >> static_cast<std::uint64_t>(16));
    x |= (x >> static_cast<std::uint64_t>(32));
    return(bitcount(x) - static_cast<std::uint64_t>(1));
  }
}

// lib/bitcount.cpp

namespace tools {
  std::uint32_t bitcount(std::uint32_t x) {
    x = (x & static_cast<std::uint32_t>(0x55555555ull)) + (x >> static_cast<std::uint32_t>(1) & static_cast<std::uint32_t>(0x55555555ull));
    x = (x & static_cast<std::uint32_t>(0x33333333ull)) + (x >> static_cast<std::uint32_t>(2) & static_cast<std::uint32_t>(0x33333333ull));
    x = (x & static_cast<std::uint32_t>(0x0f0f0f0full)) + (x >> static_cast<std::uint32_t>(4) & static_cast<std::uint32_t>(0x0f0f0f0full));
    x = (x & static_cast<std::uint32_t>(0x00ff00ffull)) + (x >> static_cast<std::uint32_t>(8) & static_cast<std::uint32_t>(0x00ff00ffull));
    return (x & static_cast<std::uint32_t>(0x0000ffffull)) + (x >> static_cast<std::uint32_t>(16) & static_cast<std::uint32_t>(0x0000ffffull));
  }

  std::uint64_t bitcount(std::uint64_t x) {
    x = (x & static_cast<std::uint64_t>(0x5555555555555555ull)) + (x >> static_cast<std::uint64_t>(1) & static_cast<std::uint64_t>(0x5555555555555555ull));
    x = (x & static_cast<std::uint64_t>(0x3333333333333333ull)) + (x >> static_cast<std::uint64_t>(2) & static_cast<std::uint64_t>(0x3333333333333333ull));
    x = (x & static_cast<std::uint64_t>(0x0f0f0f0f0f0f0f0full)) + (x >> static_cast<std::uint64_t>(4) & static_cast<std::uint64_t>(0x0f0f0f0f0f0f0f0full));
    x = (x & static_cast<std::uint64_t>(0x00ff00ff00ff00ffull)) + (x >> static_cast<std::uint64_t>(8) & static_cast<std::uint64_t>(0x00ff00ff00ff00ffull));
    x = (x & static_cast<std::uint64_t>(0x0000ffff0000ffffull)) + (x >> static_cast<std::uint64_t>(16) & static_cast<std::uint64_t>(0x0000ffff0000ffffull));
    return (x & static_cast<std::uint64_t>(0x00000000ffffffffull)) + (x >> static_cast<std::uint64_t>(32) & static_cast<std::uint64_t>(0x00000000ffffffffull));
  }
}

// main.cpp

i64& maximize(i64& x, const i64 y) {
  return x = std::max(x, y);
}

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::vector<i64> A;
  tools::read(A, N);

  const i64 MAX_DIGIT_COUNT = tools::floor_log2(1000000000000u) + 1;
  const i64 NOT_AVAILABLE = -1;
  std::vector<std::array<i64, 2>> dp(MAX_DIGIT_COUNT + 1, std::array<i64, 2>({NOT_AVAILABLE, NOT_AVAILABLE}));
  const i64 EXACT = 0;
  const i64 SMALLER = 1;
  dp[0][EXACT] = 0;
  for (i64 i = 0; i < MAX_DIGIT_COUNT; ++i) {
    const i64 d = MAX_DIGIT_COUNT - i - 1;
    i64 sum = 0;
    for (const i64& A_i : A) {
      sum += (A_i >> d) & 1;
    }
    const std::array<i64, 2> gains = {sum * tools::pow2(d), (N - sum) * tools::pow2(d)};
    const i64 K_d = (K >> d) & 1;

    if (dp[i][SMALLER] != NOT_AVAILABLE) {
      maximize(dp[i + 1][SMALLER], dp[i][SMALLER] + std::max(gains[0], gains[1]));
    }
    if (dp[i][EXACT] != NOT_AVAILABLE) {
      maximize(dp[i + 1][EXACT], dp[i][EXACT] + gains[K_d]);
      if (K_d == 1) {
        maximize(dp[i + 1][SMALLER], dp[i][EXACT] + gains[0]);
      }
    }
  }

  std::cout << std::max(dp.back()[EXACT], dp.back()[SMALLER]) << std::endl;
  return 0;
}

Measured memory_bytes: 1024