#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1e6 + 7;
ll N, K;
ll arr[INF];

bool func(ll n) {
	if (n <= 1)return false;
	n++;
	ld x = log2l(n);
	if (x == int(x) * 1.0) {
		return true;
	}
	else return false;
}

int main() {
	cin >> N >> K;
	ll ans = 0, cur = 0, cnt = K;
	for (ll i = 1; i <= N; i++) {
		cin >> arr[i];
		cur = cur | arr[i];
		if (arr[i] == 1 || i == N - cnt + 1) {
			if (cnt == K) {
				ans = cur;
			}
			else ans = ans & cur;
			cnt--;
			cur = 0;
		}
	}
	cout << ans << "\n";
}