#include <iostream>
#include <vector>

using namespace std;

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

int rmq[LOGN][MAXN], lg2[MAXN + 1];
vector<pair<int, int>> ors[MAXN];

int query(int l, int r) {
  int lg = lg2[r - l + 1];
  return rmq[lg][l] | rmq[lg][r - (1 << lg) + 1];
}

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 >> rmq[0][i];
  }
  for(int i = 2; i <= n; i++) {
    lg2[i] = 1 + lg2[i >> 1];
  }

  for(int i = 1; i <= lg2[n]; i++) {
    for(int j = 0; j + (1 << i) <= n; j++) {
      rmq[i][j] = rmq[i - 1][j] | rmq[i - 1][j + (1 << (i - 1))];
    }
  }

  for(int i = 0; i < n; i++) {
    int poz = i;
    while(poz < n) {
      int now = query(i, poz);
      ors[i].push_back({now, poz});
      int st = poz, dr = n - 1, newpoz = poz;
      while(st <= dr) {
        int mij = (st + dr) / 2;
        if(query(i, mij) == now) {
          newpoz = mij;
          st = mij + 1;
        } else {
          dr = mij - 1;
        }
      }
      poz = newpoz + 1;
    }
  }

  int answer = 0;
  for(int bit = MAXBIT - 1; bit >= 0; bit--) {
    answer += (1 << bit);
    int cnt = 0, poz = 0;
    while(poz < n && cnt < k) {
      int st = 0, dr = (int)ors[poz].size() - 1, newpoz = -1;
      while(st <= dr) {
        int mij = (st + dr) / 2;
        if((ors[poz][mij].first & answer) == answer) {
          newpoz = mij;
          dr = mij - 1;
        } else {
          st = mij + 1;
        }
      }
      if(newpoz == -1) {
        break;
      }
      cnt++;
      poz = ors[poz][newpoz].second + 1;
    }
    if(cnt < k) {
      answer -= (1 << bit);
    }
  }

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