#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 {
  vector<pair<int, int>> stiva1, stiva2;

  void init(int n) {
    stiva1.reserve(n);
    stiva2.reserve(n);
  }

  void push(int x) {
    int sp = x;
    if(!stiva1.empty()) {
      sp |= stiva1.back().second;
    }
    stiva1.push_back({x, sp});
  }

  void pop() {
    if(stiva2.empty()) {
      int sp = 0;
      while(!stiva1.empty()) {
        int x = stiva1.back().first;
        stiva1.pop_back();
        sp |= x;
        stiva2.push_back({x, sp});
      }
    }
    stiva2.pop_back();
  }

  int get() {
    int answer = 0;
    if(!stiva1.empty()) {
      answer |= stiva1.back().second;
    }
    if(!stiva2.empty()) {
      answer |= stiva2.back().second;
    }
    return answer;
  }
} qor;

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

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

  qor.init(n);
  int answer = 0;
  for(int bit = MAXBIT - 1; bit >= 0; bit--) {
    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;
}