#include <bits/stdc++.h>
using namespace std;
const int maxn = 57;
long long sum[maxn];
bool dp[maxn][maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    cin >> sum[i];
    sum[i] += sum[i - 1];
  }
  long long ans = 0;
  for (int ind = maxn; ind >= 0; ind--) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    ans |= ((long long)1 << ind);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= i; j++) {
        for (int h = 1; h <= i; h++) {
          if (((sum[i] - sum[h - 1]) & ans) >= ans) {
            dp[i][j] |= dp[h - 1][j - 1];
          }
        }
      }
    }
    if (!dp[n][k]) ans ^= ((long long)1 << ind);
  }
  cout << ans;
  return 0;
}
