#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <assert.h>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'

using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n,k;
unsigned long long dp[3000][3000];
unsigned long long a[3000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    if(k>n) {cout << 0; return 0;}
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 0; i <= n; i++) dp[0][i]=(1ULL<<62)-1;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= n; j++) {
            unsigned long long r = 0;
            for(int l = j; l >= 1; l--) {
                r|=a[l];
                dp[i][j]=max(dp[i][j], dp[i-1][l-1]&r);
            }
        }
    }
    cout<<dp[k][n];
}
