//#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, gd = true;
            for (int i = 0; i < n; i++) {
                if (f1 && a[i] == 1 || f2 && a[i] == 2) {
                    gd = false;
                    break;
                }
                else if (a[i] == 2) {
                    f1 = false;
                    f2 = true;
                }
                else if (a[i] == 1) {
                    f1 = true;
                    f2 = false;
                }
            }

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

        cout << pat << endl;
    }
}