#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int suu[n];
  int ronri[k];
  int a = n * (n + 1) / 2;
  for (int i = 0; i < n; i++) {
    cin >> suu[i];
  }
  int ii = 0;
  int bubun[(n + 1) * n / 2];
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      bubun[ii] = 0;
      for (int k = i; k <= j; k++) {
        bubun[ii] += suu[k];
      }
      ii++;
    }
  }
  sort(bubun, bubun + a);
  for (int i = 0; i < k; i++) {
    ronri[i] = bubun[a - 1];
    a--;
  }
  a = n * (n + 1) / 2;
  int ans[32];
  int binary[k][32];
  for (int i = 0; i < k; i++) {
    for (int t = 0; t < 32; t++) {
      binary[i][t] = 0;
    }
    int length = 0;
    int yy = ronri[i];
    for (int j = 0; yy > 0; j++) {
      binary[i][j] = yy % 2;
      yy = yy / 2;
      length++;
    }
  }
  int binaryans[32];
  for (int t = 0; t < 32; t++) {
    binaryans[t] = 0;
  }
  for (int i = 0; i < 32; i++) {
    for (int j = 0; j < k; j++) {
      if (j == 0)
        binaryans[i] = binary[j][i];
      else
        binaryans[i] = binaryans[i] & binary[j][i];
    }
  }
  int anss = 0;
  for (int i = 0; i < 32; i++) {
    int r = pow(2, i);
    anss += r * binaryans[i];
  }
  cout << anss << endl;
  return 0;
}
