#include <bits/stdc++.h>
using namespace std;
long long dp[66][66] = {0};
long long num[66];
long long qz[66];
long long n, m;
long long xi[66], tt = 1;
long long ans = 0;
int main() {
  cin >> n >> m;
  long long a, b, c, d, i, j;
  for (a = 1; a <= n; a++) cin >> num[a];
  for (a = 1; a <= n; a++) qz[a] = qz[a - 1] + num[a];
  for (i = 60; i >= 0; i--) {
    memset(dp, 0, sizeof dp);
    xi[tt] = i;
    dp[0][0] = 1;
    for (a = 1; a <= 50; a++)
      for (b = 1; b <= m; b++) {
        for (c = 0; c < a; c++) {
          if (!dp[c][b - 1]) continue;
          long long ju = 1;
          for (d = 1; d <= tt; d++)
            if (!((1LL << xi[d]) & (qz[a] - qz[c]))) {
              ju = 0;
              break;
            }
          if (ju == 1) {
            dp[a][b] = 1;
            break;
          }
        }
      }
    if (dp[n][m]) {
      tt++;
      ans += (1LL << i);
    }
  }
  cout << ans << endl;
  return 0;
}
