#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
bool minimize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x > y + eps) {
    x = y;
    return true;
  } else
    return false;
}
template <class X, class Y>
bool maximize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x + eps < y) {
    x = y;
    return true;
  } else
    return false;
}
template <class T>
T Abs(const T &x) {
  return (x < 0 ? -x : x);
}
int n, m;
long long value[111], sum[111];
bool f[111][111];
void init(void) {
  cin >> n >> m;
  for (int i = (1), _b = (n); i <= _b; i++) cin >> value[i];
  for (int i = (1), _b = (n); i <= _b; i++) sum[i] = sum[i - 1] + value[i];
}
bool canMatch(long long mask) {
  memset(f, false, sizeof f);
  f[0][0] = true;
  for (int i = 0, _n = (n); i < _n; i++)
    for (int j = 0, _n = (m); j < _n; j++)
      if (f[i][j])
        for (int k = (i + 1), _b = (n); k <= _b; k++) {
          long long tmp = sum[k] - sum[i];
          if ((tmp & mask) == mask) f[k][j + 1] = true;
        }
  return f[n][m];
}
void process(void) {
  long long res = 0;
  for (int pos = (1), _b = (60); pos <= _b; pos++) {
    long long tmpRes = (res << 1) ^ 1;
    long long pattern = tmpRes << (60 - pos);
    if (canMatch(pattern))
      res = tmpRes;
    else
      res = tmpRes ^ 1;
  }
  cout << res << endl;
}
int main(void) {
  init();
  process();
  return 0;
}
