#include <bits/stdc++.h>
using namespace std;
const int maxn = 66;
long long n, k, a[maxn], d[maxn][maxn];
int main(void) {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  long long rt = 0;
  for (int i = 55; i >= 0; --i) {
    rt += ((1LL * 1) << i);
    memset(d, 0, sizeof(d));
    d[0][0] = 1;
    for (int j = 1; j <= n; ++j) {
      for (int q = 1; q <= j; ++q) {
        for (int w = j - 1; w >= q - 1; --w) {
          if (((a[j] - a[w]) & rt) < rt) continue;
          if (d[w][q - 1] == 1) d[j][q] = 1;
        }
      }
    }
    if (d[n][k] == 0) rt -= ((1LL * 1) << i);
  }
  cout << rt << endl;
}
