#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>

using namespace std;

#define less less228
#define left left228
#define right right228

template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}


random_device rnd;

template<typename T> void shuffle(vector< T > &v) {
    for (int i = 1; i < (int)v.size(); ++i) {
        swap(v[rnd() % i], v[i]);
    }
    for (int i = (int)v.size() - 1; i; --i) {
        swap(v[rnd() % i], v[i]);
    }
}

const int N = 300 * 1000 + 228;

int n, k;
int stmin[N][20], stmax[N][20];
int a[N], lg[N];

void buildst() {
    lg[1] = 0;
    for (int i = 2; i <= n; ++i) {
        lg[i] = lg[i >> 1] + 1;
    }
    for (int i = 1; i <= n; ++i) {
        stmin[i][0] = stmax[i][0] = a[i];
    }
    for (int k = 1; k <= lg[n]; ++k) {
        for (int i = 1; i <= n - (1 << k) + 1; ++i) {
            stmin[i][k] = min(stmin[i][k - 1], stmin[i + (1 << (k - 1))][k - 1]);
            stmax[i][k] = max(stmax[i][k - 1], stmax[i + (1 << (k - 1))][k - 1]);
        }
    }
}

int get_min(int l, int r) {
    int k = lg[r - l + 1];
    return min(stmin[l][k], stmin[r - (1 << k) + 1][k]);
}
int get_max(int l, int r) {
    int k = lg[r - l + 1];
    return max(stmax[l][k], stmax[r - (1 << k) + 1][k]);
}

bool kek[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    buildst();
    int i = 1;
    while (i <= n - k + 1) {
        int j = i;
        while (j + 1 <= n && a[j + 1] > a[j]) {
            ++j;
        }
        for (int ptr = i; ptr <= j; ++ptr) {
            if (ptr + k - 1 <= j) {
                kek[ptr] = 1;
            }
        }
        i = j + 1;
    }
    int res = 0;
    bool is_kek = 0;
    for (int i = 1; i <= n - k + 1; ++i) {
        if (kek[i]) is_kek = 1;
        else ++res;
    }
    res += is_kek;
    for (int i = 1; i <= n - k; ++i) {
        if (kek[i] && kek[i + 1]) continue;
        // cout << "i check i=" << i << " ai=" << a[i] << " aik=" << a[i + k] << " min=" << get_min(i + 1, i + k - 1) << " max=" << get_max(i + 1, i + k - 1) << endl;
        if (a[i] < get_min(i + 1, i + k - 1) && a[i + k] > get_max(i + 1, i + k - 1)) {
            --res;
        }
    }

    cout << res << '\n';
    return 0;
}
// RU_023

/*
Нестеренкококо
нос тёр енко)))
ееео

shironury

boootgslkfjdaojfdopsjfopjso
pgjq]pogjopsjg\qrwjopg
j
pogjqwrjgp]oqwjjqw]pjljfojpjowjow4jgopja    ohbip]aeo'rogpoaj0
[bkrw
pojgqwjp\\j\;sync_with_stdiojp
ojeofmpworuc[owejgoprwig
[sdkz
pgj
p[gjes
p0ghjqsp[

jg
prsjgopjg]prwjgoprejgopjrepogjrepog]jgoprejgrgjporeqjgoperjgoprejgopeqrjgopeqrjgoprqwjgpoqjrwsopt4ng\ojsbjsoprnbfqsn\bvhqerpogjorwo
pwewh\rwh \wjiowe orw jop jgr\p jpj o jopj gr\pj p gjop j\pj\pe jp'oj [
 k
 p[eq   fj\pjfdwj\ejopjojopjopjf;'djpfsj, ipojs\p gpsdigsj gorkgjgjrogjdojgiao'fsdvopdshpdfidopcnweojccodj [cjd;ofjd[jdspmcojc"ajno[:Afvoq[w0shbprs`nm/jP{Vadmn;'fnc[Ajojsfpfjcffor 9int i= ; 1 < nfor (int i =1; for (int i =1 ; i <= n: ++i) frfor (int j = 1; j <= ml; ++'}]]]]]]]]]
5
1 5
1 2
2 3
2 4
*/

Measured memory_bytes: 36608