#include <bits/stdc++.h>
using namespace std;
const long long int md = 1e9 + 7;
const long long int N = 55;
long long int a[N];
long long int dp[N][N];
vector<pair<long long int, long long int>> v;
long long int mask;
long long int rec(long long int n, long long int k) {
  long long int s = 0;
  if (dp[n][k] != -1) return dp[n][k];
  v.emplace_back(pair<long long int, long long int>{n, k});
  if (k == 1) {
    for (long long int i = 1; i <= n; i++) s += a[i];
    return dp[n][k] = ((s & mask) == mask);
  }
  for (long long int i = n; i >= k; i--) {
    s += a[i];
    if ((s & mask) == mask)
      if (rec(i - 1, k - 1)) return dp[n][k] = 1;
  }
  return dp[n][k] = 0;
}
signed main() {
  ios::sync_with_stdio(0);
  long long int n, k;
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  long long int ans = 0;
  long long int c = pow(2, 56);
  for (long long int i = 0; i < N; i++)
    for (long long int j = 0; j < N; j++) dp[i][j] = -1;
  for (long long int i = 56; i >= 0; i--) {
    mask = ans + c;
    if (rec(n, k)) ans += c;
    c >>= 1;
    for (auto it : v) dp[it.first][it.second] = -1;
    v.clear();
  }
  cout << ans;
  return 0;
}
