#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
vector<char*> tokenizer(const char* args) {
  char* token = new char[111];
  strcpy(token, args);
  token = strtok(token, ", ");
  vector<char*> v({token});
  while (token = strtok(NULL, ", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back();
  debugg(args, T...);
}
long long mod = 1e9 + 7;
const int MX = 0x3f3f3f3f;
int n, k;
long long a[51], pre[52], dp[51][51];
int check(long long mask) {
  int i, j, x;
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= i; j++) {
      if (((pre[i] - pre[j]) & mask) == mask) {
        for (x = 0; x <= k - 1; x++)
          if (dp[j][x]) dp[i][x + 1] = 1;
      }
    }
  }
  return dp[n][k];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i;
  cin >> n >> k;
  for (i = 0; i <= n - 1; i++) {
    cin >> a[i];
    pre[i + 1] = pre[i] + a[i];
  }
  long long ans = 0;
  for (i = 56; i >= 0; i--) {
    if (check(ans | 1ll << i)) ans |= 1ll << i;
  }
  cout << ans;
  return 0;
}
