#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6;
int v[nmax+2];
signed main()
{
    int n , k ;
    cin >> n >> k ;
    for ( int i = 1 ; i <= n ; ++ i ) cin >> v[i];
    int nr1 = 0 ;
    int nr2 = 0 ;
    for ( int i = 1;  i <= n ; ++ i )
    if ( v[i] == 1 ) ++ nr1 ;
    else if ( v[i] == 2 ) ++ nr2 ;
    if ( nr1 + nr2 < k ) cout << 0 ;
    else if ( nr2 >= k && nr1 >= k ) cout << 3 ;
    else if ( nr2 >= k ) cout << 2 ;
    else cout << 1 ;
    return 0;
}
