#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;

void solve () {
    ll n, k; cin >> n >> k;

    vector<ll> v(n);
    for (ll& x : v) cin >> x;


    ll cnt1 = count(v.begin(), v.end(), 1), cnt0 = count(v.begin(), v.end(), 0);

    if (cnt1 + cnt0 == n) {
        if (cnt1 >= k) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }

    vector<ll> cors;
    for (ll i = 0; i < n; ++i) {
        if (v[i] == 2) {
            cors.push_back(i); 
           
        }
    }

    if (cors.size() < k) {
        cout << 0 << endl; return;
    }

    ll fin = 0;
    ll res = -1;
    for (ll cor : cors) {
        ll cur_res = 0;
       // cout << cor << endl;
        for (ll i = fin; i <= cor; ++i) {
            //cout << v[i] << ' ';
            cur_res |= v[i];
        }
        //cout << cur_res << endl;
        fin = cor + 1;
        if (res == -1) res = cur_res;
        else {
            res = (res & cur_res);
        }
    }

    cout << res << endl;
}

signed main () {
    ll t = 1; //cin >> t;

    for (ll cs = 1; cs <= t; ++cs) {
        // cout << "Case " << cs << ": " << endl;
        solve ();
    }
}   