#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 ans = 0;

void rec(int i, int _or, int br, int _and) {
    if(br>k) return;
    if(i>n) {
        if(br==k) ans=max(ans, _and);
        return;
    }
    rec(i+1, _or|a[i], br, _and);
    rec(i+1, a[i], br+1, _and&_or);
}
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];}
    rec(1, 0, 1, (1<<30)-1);
    cout<<ans;
}
