#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[60], ans, f[60][60];
bool chk(long long x) {
  memset(f, 0, sizeof(f)), 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++)
        f[i][j] |= f[k][j - 1] & ((a[i] - a[k] & x) == x);
  return f[n][m];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), a[i] += a[i - 1];
  for (int i = 60; i >= 0; i--)
    if (chk(ans | (1ll << i))) ans |= (1ll << i);
  cout << ans;
  return 0;
}
