#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <bitset>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

ll pow[POW_MAX + 2];

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}

ll comb(int n, int r) {
  return (((pow[n] * mod_inv(pow[r])) % MOD) * mod_inv(pow[n - r])) % MOD;
}

int const N_MAX = 1e5;

int N;
ll K;
ll A[N_MAX + 1];

int main() {
  scanf("%d %lld", &N, &K);
  rep(i, N) scanf("%lld", &A[i]);

  int ones[41] = {};
  int zeros[41] = {};
  rep(i, N) {
    bitset<41> bi(A[i]);
    string s = bi.to_string();
    rep(j, 41) {
      if (s[j] == '1') ones[j]++;
      else zeros[j]++;
    }
  }

  ll base = 1;
  ll max_f = 0;
  ll x = 0;
  repr(i, 40) {
    if (i < 40) base *= 2;

    bool zero = ones[i] < zeros[i];
    if (zero) x += base;

    if (zero && x <= K) {
      max_f += base * zeros[i];
    } else {
      max_f += base * ones[i];
    }
  }
  printf("%lld\n", max_f);
}
