#include <bits/stdc++.h>
struct IO_Tp {
  inline bool is_digit(const char ch) { return '0' <= ch && ch <= '9'; }
  inline IO_Tp& operator>>(int& res) {
    res = 0;
    static char ch;
    while (ch = getchar(), !is_digit(ch))
      ;
    do (res *= 10) += ch & 15;
    while (ch = getchar(), is_digit(ch));
    return *this;
  }
  inline IO_Tp& operator>>(long long& res) {
    res = 0;
    static char ch;
    while (ch = getchar(), !is_digit(ch))
      ;
    do (res *= 10) += ch & 15;
    while (ch = getchar(), is_digit(ch));
    return *this;
  }
} IO;
const int Max_N(55);
int N, K;
long long a[Max_N];
bool F[Max_N][Max_N];
int main(int argc, char** argv) {
  IO >> N >> K;
  for (int i(1); i <= N; ++i) IO >> a[i], a[i] += a[i - 1];
  long long Ans(0);
  for (int w(59); w >= 0; --w) {
    F[0][0] = 1;
    Ans |= 1LL << w;
    for (int i(1); i <= N; ++i)
      for (int j(1); j <= K; ++j) {
        F[i][j] = false;
        for (int k(0); k != i; ++k)
          F[i][j] |= F[k][j - 1] && ((a[i] - a[k]) & Ans) == Ans;
      }
    if (!F[N][K]) Ans ^= 1LL << w;
  }
  printf("%I64d", Ans);
  return 0;
}
