#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
long long a[maxn], s[maxn];
long long ans;
int n, m;
bool dp[maxn][maxn];
long long sum(int l, int r) { return s[r] - s[l - 1]; }
bool check(int x) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
      for (int k = j; k <= i; ++k) {
        dp[i][j] |= dp[k - 1][j - 1] && ((sum(k, i) & ans) == ans) &&
                    (sum(k, i) & ((long long)1 << x));
      }
    }
  }
  return dp[n][m];
}
int main() {
  while (cin >> n >> m) {
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      s[i] = s[i - 1] + a[i];
    }
    ans = 0;
    for (int i = 56; i >= 0; --i) {
      if (check(i)) ans |= ((long long)1 << i);
    }
    cout << ans << endl;
  }
  return 0;
}
