#include <bits/stdc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;

constexpr int N = 2e+5 + 5, oo = 2e+18;

void _() {
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = 0;
  for (int mask = 0; mask < (1LL << n); ++mask) {
    int cnt = __builtin_popcount(mask);
    if (cnt != k || !(mask & 1)) {
      continue;
    }
    int val = 0, cost = -1;
    for (int i = 0; i < n; ++i) {
      int bit = (mask & (1LL << (n - i - 1)));
      val |= a[i];
      if (bit) {
        cost &= val;
        val = 0;
      }
    }
    ans = max(ans, cost);;
  }
  cout << ans << '\n';
}

signed main() {
  pasha
  int t = 1;
  // cin >> t;
  for (int cs = 1; cs <= t; ++cs) {
    _();
    // cout << '\n';
  }
}