#include <iostream>
#include <vector>

using namespace std;

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

int v[MAXN], nxt[MAXN];

struct QueueOR {
  pair<int, int> stiva1[MAXN], stiva2[MAXN];
  int sp1, sp2;

  void push(int x) {
    int sp = x;
    if(sp1 > 0) {
      sp |= stiva1[sp1 - 1].second;
    }
    stiva1[sp1++] = {x, sp};
  }

  void pop() {
    if(sp2 == 0) {
      int sp = 0;
      for(; sp1 > 0; sp1--) {
        int x = stiva1[sp1 - 1].first;
        sp |= x;
        stiva2[sp2++] = {x, sp};
      }
    }
    sp2--;
  }

  int get() {
    int answer = 0;
    if(sp1 > 0) {
      answer |= stiva1[sp1 - 1].second;
    }
    if(sp2 > 0) {
      answer |= stiva2[sp2 - 1].second;
    }
    return answer;
  }
} qor;

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]);
  }

  int answer = 0;
  for(int bit = MAXBIT - 1; bit >= 0; bit--) {
    if((1 << bit) > maxim) {
      continue;
    }
    answer += (1 << bit);
    int j = 0;
    for(int i = 0; i < n; i++) {
      while(j < n && (qor.get() & answer) != answer) {
        qor.push(v[j++]);
      }
      if((qor.get() & answer) == answer) {
        nxt[i] = j;
      } else {
        nxt[i] = -1;
      }
      qor.pop();
    }

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

    if(cnt < k) {
      answer -= (1 << bit);
    }
  }

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