#include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=-;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> line(N);
    vector<int> dl;
    foreach(i, line)cin>>i;
    int ans = 0;
    for(int i=1;i<N;++i){
        dl.assign(N, INF);
        REP(j, i){
            if(line[j] < i)continue;
            *upper_bound(ALL(dl), line[j])=line[j];
        }
        ans = max(ans, (int)(lower_bound(ALL(dl), INF) - dl.begin()));
    }
    cout << min(ans+K, N/2) << endl;
    return 0;
}

