#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

//幅wの区間の最大値を返すスライド最大値。計算量はO(n)
vector<ll> slidemax(const vector<ll> &seq, ll w) {
    vector<ll> ans;
    deque<ll> deq;
    ll l = 0, n = seq.size();
    REP(r, 0, n) {
        while(!deq.empty() && seq[deq.back()] <= seq[r]) {
            deq.pop_back();
        }
        deq.push_back(r);
        if (r >= w) {
            if (deq.front() == l) {
                deq.pop_front();
            }
            l++;
            ans.push_back(seq[deq.front()]);
        }
        //ans.push_back(seq[deq.front()]); //最初w個を詰めているときの最大値も欲しい場合はこっちを使う
    }
    return ans;
}

vector<ll> slidemin(const vector<ll> &seq, ll w) {
    vector<ll> ans;
    deque<ll> deq;
    ll l = 0, n = seq.size();
    REP(r, 0, n) {
        while(!deq.empty() && seq[deq.back()] >= seq[r]) {
            deq.pop_back();
        }
        deq.push_back(r);
        if (r >= w) {
            if (deq.front() == l) {
                deq.pop_front();
            }
            l++;
            ans.push_back(seq[deq.front()]);
        }
        //ans.push_back(seq[deq.front()]);
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> P(N);
    ll minnum = llmax;
    ll maxnum = 0;
    REP(i, 0, N) {
        cin >> P[i];
        if (i < K) {
            if (minnum > P[i]) {
                minnum = P[i];
            }
            if (maxnum < P[i]) {
                maxnum = P[i];
            }
        }
    }
    vector<ll> maxpre = slidemax(P, K);
    vector<ll> minpre = slidemin(P, K);
    vector<ll> maxseq;
    maxseq.push_back(maxnum);
    REP(i, 0, maxpre.size()) {
        maxseq.push_back(maxpre[i]);
    }
    vector<ll> minseq;
    minseq.push_back(minnum);
    REP(i, 0, minpre.size()) {
        minseq.push_back(minpre[i]);
    }
    ll updn[N - 1];
    REP(i, 0, N - 1) {
        if (P[i] < P[i + 1]) {
            updn[i] = 1;
        } else {
            updn[i] = 0;
        }
    }
    bool allok[N - K + 1];
    ll tmp = 0;
    REP(i, 0, K - 1) {
        if (updn[i] == 0) {
            tmp++;
        }
    }
    REP(i, 0, N - K) {
        // cout << tmp << endl;
        if (tmp == 0) {
            allok[i] = true;
        } else {
            allok[i] = false;
        }
        if (updn[i] == 0) {
            tmp--;
        }
        if (updn[i + K - 1] == 0) {
            tmp++;
        }
    }
    if (tmp == 0) {
        allok[N - K] = true;
    } else {
        allok[N - K] = false;
    }
    // REP(i, 0, N - K + 1) {
    //     cout << allok[i] << " ";
    // }
    // cout << endl;
    ll num = 1;
    bool used = false;
    REP(i, 0, N - K) {
        if (allok[i + 1]) {
            if (!used && !allok[0]) {
                num++;
                // cout << i << "aaa" << endl;
            }
            used = true;
            continue;
        }
        if (P[i] == minseq[i] && P[i + K] >= maxseq[i]) {
            continue;
        }
        num++;
        // cout << i << "bbb" << endl;
    }
    cout << num << endl;
}


Measured memory_bytes: 9972