#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1000000;
const int LOGN = 20;
const int MAXBIT = 30;

int v[MAXN], nxt[MAXN], prv[MAXN];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  int maxim = 0;
  for(int i = 0; i < n; i++) {
    cin >> v[i];
    maxim = max(maxim, v[i]);
    prv[i] = i;
  }

  int answer = 0;
  for(int bit = MAXBIT - 1; bit >= 0; bit--) {
    if((1 << bit) > maxim) {
      continue;
    }
    int j = 0, have = 0;
    for(int i = 0; i < n; i++) {
      while(j < prv[i]) {
        if(v[j] & (1 << bit)) {
          have++;
        }
        j++;
      }
      while(j < n && have == 0) {
        if(v[j] & (1 << bit)) {
          have++;
        }
        j++;
      }
      if(have && prv[i] >= 0) {
        nxt[i] = j;
      } else {
        nxt[i] = -1;
      }
      if(v[i] & (1 << bit)) {
        have--;
      }
    }

    int poz = 0, cnt = 0;
    while(poz < n && cnt < k) {
      if(nxt[poz] == -1) {
        break;
      }
      poz = nxt[poz];
      cnt++;
    }

    if(cnt >= k) {
      for(int i = 0; i < n; i++) {
        prv[i] = nxt[i];
      }
      answer += (1 << bit);
    }
  }

  cout << answer << "\n";
  return 0;
}