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

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

    cin >> n >> k;
    int mx=0;
    for(int i = 1; i <= n; i++) {cin >> a[i]; mx=max(mx, a[i]);}
    int currans = 0;
    for(long long z = 0; (1<<z)<=mx; z++) {
        //cout << currans << endl;
        for(long long bit = log2(mx)+1; bit>=0; bit--) {
            int ans = currans|(1LL<<bit);
            if(currans&(1LL<<bit)) continue;
            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) {
                currans = ans;
                break;
            }
        }
    }
    cout<<currans;

}
/*
10 5
5 1 3 2 9 8 10 2 17 3

31 1
30 1
29 1
28 1
27 1
26 1
25 1
24 1
23 1
22 1
21 1
20 1
19 1
18 1
17 1
16 1
15 1
14 1
13 1
12 1
11 2  1011
10 2  1010
9 2  1001
8 3  1000
7 1  0111
6 1  0110
5 1  0101
4 1  0100
3 4  0011
2 5  0010
1 6  0001
0 11  0000

8 3  1000

ako 1000 ne stava, togava 1001, 1100, ... ne stavat
*/
