#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=100100100100100;
const int MAXR=500010;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
    	int t;is>>t;
    	x=t;
    	return (is);
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD=1000000007;
using mint=Fp<MOD>;

template<typename T>
T pow(const T &a,int n){
  if(n==0)return 1;
  T x=pow(a,n/2);
  x=x*x;
  if(n&1)x*=a;
  return x;
}
 
mint fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];
//テーブルの作成
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<=MAXR;i++){
        fac[i]=fac[i-1]*mint(i);
        inv[i]=-inv[MOD%i]*mint(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}

//演算部分
mint COM(int n,int k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*finv[k]*finv[n-k];
}
int s[1010];
bool dp[50][600000];
signed main(){
  int n,k;cin>>n>>k;
  rep(i,n){
    int x;cin>>x;
    s[i+1]=s[i]+x;
  }
  ivec po;
  for(int i=0;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      po.pb(s[j]-s[i]);
    }
  }
  int m=po.size();
  /*rep(i,m){
    cout<<po[i]<<endl;
  }*/
  rep(bi,50){
    rep(i,m){
      if((po[i]>>bi)%2==1)dp[bi][i]=1;
      else dp[bi][i]=0;
    }
  }
  vector<bool> res(m,1);
  int ans=0;
  for(int bi=49;bi>=0;bi--){
    int sum=0;
    for(int i=0;i<m;i++){
      if(res[i] & dp[bi][i])sum++;
    }
    //cout<<bi<<" "<<sum<<endl;
    if(sum>=k){
      for(int i=0;i<m;i++){
        res[i]=res[i] & dp[bi][i];
      }
      ans+=(1LL<<bi);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 31944