#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/

using namespace __gnu_pbds;
using namespace std;


#define ll long long
#define ld long double
#define mp make_pair
#define what_is(x) cerr << #x << " is " << x << endl;

typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

/*
int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}
*/
vector<int> Z(vector<int> s)
{
    int n = s.size();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R-L] == s[R]) R++;
            z[i] = R-L; R--;
        } else {
            int k = i-L;
            if (z[k] < R-i+1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R-L] == s[R]) R++;
                z[i] = R-L; R--;
            }
        }
    }
    return z;
}

mt19937 rnd(time(0));
/*
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct CHT : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a /b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
        isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};
*/

int n, k;
vector<int> p;

vector<vector<int>> sp_min(20);
vector<vector<int>> sp_max(20);

void init()
{
    for (int i = 0; i<n; i++) sp_min[0].push_back(p[i]);
    for (int iter = 1; (1<<iter)<=n; iter++)
    {
        int N = (1<<iter);
        for (int i = 0; i+N<=n; i++) sp_min[iter].push_back(min(sp_min[iter-1][i], sp_min[iter-1][i+N/2]));
    }

    for (int i = 0; i<n; i++) sp_max[0].push_back(p[i]);
    for (int iter = 1; (1<<iter)<=n; iter++)
    {
        int N = (1<<iter);
        for (int i = 0; i+N<=n; i++) sp_max[iter].push_back(max(sp_max[iter-1][i], sp_max[iter-1][i+N/2]));
    }

}

int find_min(int l, int r)
{
    int k = 0;
    while ((1<<(k+1))<=(r-l+1)) k++;
    int N = 1<<k;
    return min(sp_min[k][l], sp_min[k][r-N+1]);
}

int find_max(int l, int r)
{
    int k = 0;
    while ((1<<(k+1))<=(r-l+1)) k++;
    int N = 1<<k;
    return max(sp_max[k][l], sp_max[k][r-N+1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);


    cin>>n>>k;
    p.resize(n);
    for (int i = 0; i<n; i++) cin>>p[i];
    vector<int> cmp(n-1);
    for (int i = 0; i<n-1; i++) cmp[i] = (p[i+1]>p[i]);

    vector<int> pref(n-k+1);
    for (int i = 0; i<k-1; i++) pref[0]+=cmp[i];
    for (int i = 1; i<n-k+1; i++) {pref[i] = pref[i-1] - cmp[i-1] + cmp[i-2+k];}

    init();


    //for (int i = 0; i<n-k+1; i++) cout<<pref[i]<<' ';
    //cout<<endl;

    int total = 0;
    bool same = false;
    for (int i = 0; i<n-k+1; i++) if (pref[i]==k-1) same = true;
    total+=same;
    for (int i = 0; i<n-k+1; i++) if (pref[i]!=k-1)
    {
        //cout<<i<<": "<<total<<endl;
        if (i==0) {total++;
            continue;}
        if (pref[i-1]==k-1) {total++;
            continue;}
        //i..i+k-2
        if (p[i-1]>find_min(i, i+k-2)||p[i+k-1]<find_max(i, i+k-2)) total++;
    }
    cout<<total;


}

Measured memory_bytes: 29556