//#include "partition.h"
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <set>
#include <cmath>

#define ll long long
#define sz size()
#define cY cout << "YES" << endl;
#define cN cout << "NO" << endl;
#define pb push_back
#define F first
#define S second
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


/*
"0.000..."   setprecision(---) + fixed
"USACO"      freopen("---", "r", stdin); freopen("---", "w", stdout);
"Matrix"     vector <vector <int>> ---(---, vector <int> (---));
"NOD"        __gcd
"NOK"        a * b / __gcd(a,b)
*/

using namespace std;

//cout << "!! !!" << endl;
int main() {
    //cout << "?? ??" << endl;
    FASTIO
    ll T_T = 1;
    //cin >> T_T;
    while (T_T--) {
        ll n, k;
        cin >> n >> k;

        vector <ll> a(n);
        ll sum1 = 0, sum2 = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (a[i] == 1) {
                sum1++;
            }
            else if (a[i] == 2) {
                sum2++;
            }
        }

        ll pat = 0, sum = 0;
        

        if (sum1 >= k && sum2 >= k) {
            pat = 2;
            bool f1 = false, f2 = false;
            ll sm = 0;
            for (int i = 0; i < n; i++) {
                if (sm >= k) {
                    break;
                }

                if (a[i] == 2) {
                    if (f1) {
                        f1 = false;
                        sm++;
                    }
                    else {
                        f2 = true;
                    }
                }
                else if (a[i] == 1) {
                    if (f2) {
                        f2 = false;
                        sm++;
                    }
                    else {
                        f1 = true;
                    }
                }
            }

            if (sm >= k) {
                pat = 3;
            }
        }
        else if (sum1 >= k) {
            pat = 1;
        }
        else if (sum2 >= k) {
            pat = 2;
        }

        cout << pat << endl;
    }
}