#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;
long long dp[3000][3000];
long long a[3000];

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

    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int ans = 2000; ans >= 0; ans--) {
        int br=0, r=0;
        for(int i = 1; i <= n; i++) {
            r|=a[i];
            if((r&ans)==ans) {
                r = 0;
                br++;
            }
        }
        if((r&ans)==ans) {
            br++;
        }
        if(br>=k) {
            cout << ans;
            return 0;
        }
    }
}
