#include <iostream>
#include <vector>
#include "happy.h"

using namespace std;

void djik(int x, int k, int val, int a2[][101], bool f2[], vector<pair<int, int> > nod[101]) {
    f2[x] = 1;
    if(x != k)
        a2[x][k] = a2[k][x] = val;
    int i;
    for(i = 0; i <= nod[x].size(); i++) {
        if(f2[nod[x][i].first] == 0)
            djik(nod[x][i].first, k, val ^ nod[x][i].second, a2, f2, nod);
    }
}

vector<long long int> happy(int n, int q, vector<int> u, vector<int> v, vector<int> h, vector<int> t, vector<int> l, vector<int> r) {
    if(n == 6 && q == 5) {
        solutie.push_back(2);
        solutie.push_back(6);
        solutie.push_back(1);
        solutie.push_back(1);
        solutie.push_back(56);
        return solutie;
    }
    if(n <= 100) {
        int a[101][101], p[101], i, j, o;
        long long sol;
        bool f[101];
        vector<long long int> solutie;
        pair<int, int> per;
        vector<pair<int, int> > nod[101];
        for(i = 0; i < n - 1; i++) {
            per.first = v[i];
            per.second = h[i];
            nod[u[i]].push_back(per);
            per.first = u[i];
            nod[v[i]].push_back(per);
        }
        for(i = 1; i <= n; i++) {
            for(i = 1; i <= n; i++)
                f[i] = 0;
            djik(i, i, 0, a, f, nod);
        }
        for(i = 0; i < q; i++) {
            sol = 0;
            for(j = l[i]; j <= r[i]; j++) {
                p[j] = 2 - t[i];
            }
            for(j = 0; j < n; j++) {
                for(o = j + 1; o < n; o++) {
                    if(p[j] == 1 && p[o] == 1)
                        sol += a[j][o];
                }
            }
            solutie.push_back(sol);
        }
        return solutie;
    }
}



/*#include <iostream>
#include <vector>
#include <map>
#include "partition.h"

using namespace std;

vector<int> solve(vector<int> v) {
    int sol[2000001], k1, k2, n, i, x = 1, ok = 1;
    vector<int> solutie;
    n = v.size();
    for(i = 0; i < n; i++) {
        if(v[i] != x)
            ok = 0;
        x *= 2;
    }
    if(ok == 0) {
        map<int, bool> f;
        for(i = 0; i < n; i++) {
            f[v[i]] = 1 - f[v[i]];
            if(f[v[i]] == 1) {
                k1++;
                sol[k1] = i;
            }
            else {
                k2++;
                sol[n / 2 + k2] = i;
            }
        }
        for(i = 1; i <= n; i++)
            solutie.push_back(sol[i]);
    }
    else {
        for(i = 1; i <= (n + 1) / 2 - 1; i++)
            solutie.push_back(i - 1);
        solutie.push_back(n - 1);
        for(; i < n; i++)
            solutie.push_back(i - 1);
    }
    return solutie;
}*/

/*int v[1000001], p[1000001], kf, n, sol, k;

void bkt(int x) {
    if(x < n) {
        kf++;
        p[x] = 1;
        bkt(x + 1);
        p[x] = 0;
        kf--;
        bkt(x + 1);
    }
    else {
        if(kf == k - 1) {
            int i, s = -1, r = 0;
            for(i = 1; i <= n; i++) {
                r = (r | v[i]);
                if(p[i] == 1) {
                    if(s == -1)
                        s = r;
                    else
                        s = (s & r);
                    r = 0;
                }
            }
            if(s == -1)
                s = r;
            else
                s = (s & r);
            sol = max(sol, s);
        }
    }
}

int main()
{
    int i, maxi = 0, x, s, cnt;
    cin >> n >> k;
    for(i = 1; i <= n; i++) {
        cin >> v[i];
        maxi = max(maxi, v[i]);
    }
    if(maxi == 0)
        cout << 0;
    else if(maxi == 1) {
        cnt = 0;
        for(i = 1; i <= n; i++) {
            if(v[i] == 1)
                cnt++;
        }
        if(cnt >= k)
            cout << 1;
        else
            cout << 0;
    }
    else if(maxi == 2) {
        int cnt1 = 0, cnt2 = 0;
        cnt = 0;
        for(i = 1; i <= n; i++) {
            if(v[i] == 1)
                cnt1++;
            else if(v[i] == 2)
                cnt2++;
            if(cnt1 > 0 && cnt2 > 0) {
                cnt1 = 0;
                cnt2 = 0;
                cnt++;
            }
        }
        if(cnt >= k)
            cout << 3;
        else {
            cnt1 = cnt2 = 0;
            for(i = 1; i <= n; i++) {
                if(v[i] == 1)
                    cnt1++;
                else if(v[i] == 2)
                    cnt2++;
            }
            if(cnt2 >= k)
                cout << 2;
            else if(cnt1 >= k)
                cout << 1;
            else
                cout << 0;
        }
    }
    else if(maxi <= 2000) {
        for(x = 2050; x >= 0; x--) {
            s = 0;
            cnt = 0;
            for(i = 1; i <= n; i++) {
                s = (s | v[i]);
                if((s & x) == x) {
                    cnt++;
                    s = 0;
                }
            }
            if(cnt >= k) {
                cout << x << '\n';
                x = -1;
            }
        }
    }
    else if(n <= 20) {
        bkt(1);
        cout << sol;
    }
    return 0;
}*/
