#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[110], s[110];
bool f[110][110];
bool check(long long x) {
  fill(f[0], f[0] + 110 * 110, 0);
  f[0][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      for (int k = 0; k < i; ++k)
        if ((s[i] - s[k] & x) == x) f[i][j] |= f[k][j - 1];
  return f[n][m];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i], s[i] = s[i - 1] + a[i];
  long long ans = 0;
  for (int i = 60; ~i; --i)
    if (check(ans | 1ll << i)) ans |= 1ll << i;
  cout << ans << "\n";
  return 0;
}
