#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int maxn = 59;
const double pi = 3.14159265358979323846264;
const long long inf = 1e18;
const long long mod = 998244353;
long long op[maxn];
int dp[maxn][maxn];
int n, k;
void hj(vector<int>& pq) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int j = 1; j <= n; ++j) {
    for (int io = 1; io <= min(j, k); ++io) {
      long long la = 0;
      for (int jk = j; jk > io - 1; --jk) {
        la += op[jk];
        int fg = 1;
        for (int kl = 0; kl < pq.size(); ++kl)
          if (!(la >> pq[kl] & 1)) {
            fg = 0;
            break;
          }
        if (fg && dp[jk - 1][io - 1]) {
          dp[j][io] = 1;
          break;
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> op[i];
  vector<int> pq;
  pq.clear();
  for (int i = 56; i >= 0; --i) {
    pq.push_back(i);
    hj(pq);
    if (!dp[n][k]) pq.pop_back();
  }
  long long ans = 0;
  for (int i = 0; i < pq.size(); ++i) {
    ans |= (1ll << pq[i]);
  }
  cout << ans;
  return 0;
}
