#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cout << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cout << ", ";
    cout << *i;
  }
  cout << "]";
  cout << endl;
}
int dp[55][55];
long long a[55];
long long mask;
int f(int n, int k) {
  if (n == 0) return k == 0;
  if (k == 0) return 0;
  int& ans = dp[n][k];
  if (~ans) return ans;
  ans = 0;
  long long sum = 0;
  for (auto it = (n); it >= (1); --it) {
    sum += a[it];
    if ((sum & mask) == mask) ans |= f(it - 1, k - 1);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (auto i = (1); i <= (n); ++i) cin >> a[i];
  for (auto i = (60); i >= (0); --i) {
    memset(dp, -1, sizeof dp);
    mask |= (1LL << i);
    if (!f(n, k)) mask ^= (1LL << i);
  }
  cout << mask;
  return 0;
}
