#include <bits/stdc++.h>
using namespace std;
long long dp[55][55];
bool solve(long long i, long long j, long long n, long long k, long long arr[],
           long long curr1) {
  if (dp[i][j] != -1) return dp[i][j];
  if ((n - i) < (k - j)) {
    dp[i][j] = 0;
    return 0;
  }
  if (j == k) {
    long long sum1 = 0;
    for (long long i1 = i; i1 < n; i1++) sum1 += arr[i1];
    dp[i][j] = (curr1 == (curr1 & sum1));
    return dp[i][j];
  }
  long long sum = 0;
  bool pos = 0;
  for (long long i1 = i; i1 < n; i1++) {
    sum += arr[i1];
    if ((sum & curr1) != curr1) continue;
    if ((i1 + 1 != n) && (j != k))
      pos = pos | solve(i1 + 1, j + 1, n, k, arr, curr1);
  }
  dp[i][j] = pos;
  return pos;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  long long curr = 0;
  for (long long i = 57; i > -1; i--) {
    long long curr1 = curr + (long long)((long long)1 << (long long)i);
    memset(dp, -1, sizeof(dp));
    dp[n - 1][k] = (curr1 == ((curr1)&arr[n - 1]));
    bool temp = solve(0, 1, n, k, arr, curr1);
    if (temp == 1) curr = curr1;
  }
  cout << curr;
  return 0;
}
