#include <iostream>
#include <vector>	
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

using namespace std;
int mx = 0;
int n, k;
vector<int>a;
void rec(vector<int>b, int last) {
	if (b.size() == k - 1) {
		if (k == 2) {
			int k1 = a[0], k2 = a[b[0] + 1];
			for (int i = 1; i <= b[0]; i++) {
				k1 |= a[i];
			}
			for (int i = b[0] + 2; i < n; i++) {
				k2 |= a[i];
			}
			mx = max(mx, k1 & k2);
			return;
		}
		int ans = 0;
		for (int i = 0; i < b.size(); i++) {
			if (i == 0) {
				int c = a[0];
				for (int j = 1; j <= b[i]; j++) {
					c |= a[j];
				}
				ans = c;
			}
			else{
				int c = a[b[i - 1] + 1];
				for (int j = b[i - 1] + 2; j <= b[i]; j++) {
					c |= a[j];
				}
				ans &= c;
			}
		}
		int c = a[b[k - 2] + 1];
		for (int i = b[k - 2] + 2; i <= n - 1; i++) {
			c |= a[i];
		}
		mx = max(mx, ans & c);
		return;
	}
	for (int i = last + 1; i < n - 1; i++) {
		b.push_back(i);
		rec(b, i);
		b.pop_back();
	}
	if (last == n - 2) {
		return;
	}
}
int main() {
	cin >> n >> k;
	int mn = 0;
	int cnt1 = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a.push_back(x);
		mn = max(mn, x);
		cnt1 += (x == 1);
	}
	if (k == 1) {
		int c = a[0];
		for (int i = 1; i < n; i++) {
			c |= a[i];
		}
		cout << c << endl;

	}
	if (mn <= 1) {
		if (k <= cnt1) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
		return 0;
	}
	vector<int>c;
	rec(c, -1);
	cout << mx << endl;
}