#include <iostream>
#include <vector>

using namespace std;

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

int v[MAXN];
vector<pair<int, int>> ors[MAXN];

struct SegmentTree {
  int tree[4 * MAXN], n;

  void build(int node, int left, int right) {
    if(left == right) {
      tree[node] = v[left];
    } else {
      int middle = (left + right) / 2;
      build(2 * node, left, middle);
      build(2 * node + 1, middle + 1, right);
      tree[node] = tree[2 * node] | tree[2 * node + 1];
    }
  }

  void init(int n) {
    this->n = n;
    build(1, 0, n - 1);
  }

  int query(int node, int left, int right, int qleft, int qright) {
    if(qleft <= left && right <= qright) {
      return tree[node];
    }
    int middle = (left + right) / 2, answer = 0;
    if(qleft <= middle) {
      answer |= query(2 * node, left, middle, qleft, qright);
    }
    if(middle < qright) {
      answer |= query(2 * node + 1, middle + 1, right, qleft, qright);
    }
    return answer;
  }

  int query(int st, int dr) {
    return query(1, 0, n - 1, st, dr);
  }

  int binarySearch(int node, int left, int right, int poz, int val) {
    if(left == right) {
      return poz;
    }
    int middle = (left + right) / 2;
    if(poz > middle) {
      return binarySearch(2 * node + 1, middle + 1, right, poz, val);
    }
    int ret = binarySearch(2 * node, left, middle, poz, val);
    if(ret == middle && (v[middle + 1] & val) == v[middle + 1]) {
      ret = binarySearch(2 * node + 1, middle + 1, right, poz, val);
    }
    return ret;
  }

  int binarySearch(int poz, int val) {
    return binarySearch(1, 0, n - 1, poz, val);
  }
} aint;

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

  aint.init(n);

  for(int i = 0; i < n; i++) {
    int poz = i;
    while(poz < n) {
      int now = aint.query(i, poz);
      ors[i].push_back({now, poz});
      poz = aint.binarySearch(poz, now) + 1;
    }
  }

  int answer = 0;
  for(int bit = MAXBIT - 1; bit >= 0; bit--) {
    if((1 << bit) > maxim) {
      continue;
    }
    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;
}