#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = 4 * atan(1);

#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
   // freopen(FOUT, "w", stdout);
    fast_io();
}
const int INF = 1e9;
template<class T, int SZ> struct MinSeg { // SZ doesn't have to be power of 2
    const T ID = INF; // comb(ID,b) must equal b
    T comb(T a, T b) { return min(a, b); } // easily change this to min or max

    T seg[2*SZ];
    MinSeg() { memset(seg,0,sizeof seg); }

    void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }

    void upd(int p, T value) {  // set value at position p
        seg[p += SZ] = value;
        for (p /= 2; p; p /= 2) pull(p);
    }

    T query(int l, int r) {  // sum on interval [l, r]
        T resl = ID, resr = ID; // make sure non-commutative operations work
        for (l += SZ, r += SZ+1; l < r; l /= 2, r /= 2) {
            if (l&1) resl = comb(resl,seg[l++]);
            if (r&1) resr = comb(seg[--r],resr);
        }
        return comb(resl,resr);
    }
};
template<class T, int SZ> struct MaxSeg { // SZ doesn't have to be power of 2
    const T ID = 0; // comb(ID,b) must equal b
    T comb(T a, T b) { return max(a, b); } // easily change this to min or max

    T seg[2*SZ];
    MaxSeg() { memset(seg,0,sizeof seg); }

    void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }

    void upd(int p, T value) {  // set value at position p
        seg[p += SZ] = value;
        for (p /= 2; p; p /= 2) pull(p);
    }

    T query(int l, int r) {  // sum on interval [l, r]
        T resl = ID, resr = ID; // make sure non-commutative operations work
        for (l += SZ, r += SZ+1; l < r; l /= 2, r /= 2) {
            if (l&1) resl = comb(resl,seg[l++]);
            if (r&1) resr = comb(seg[--r],resr);
        }
        return comb(resl,resr);
    }
};
const int MAX = 2e5 + 5;
MaxSeg<int, (1<<18)> seg1;
MinSeg<int, (1<<18)> seg2;
vector<int> p;
int len[MAX];
int main(){
    fast_io();
    int n, k;
    cin >> n >> k;
    f0r(i, n){
        int pi;
        cin >> pi;
        p.eb(pi);
        seg1.upd(i, pi);
        seg2.upd(i, pi);
    }
    int ans = 0;
    int run = 0;
    f0r(i, n-k+1){
        if(i == 0){
            len[i] = 0;
            for(int j = k-1; j>= 0; j--){
                if(j == k-1){
                    len[i]++;
                    continue;
                }
                if(p[j]>p[j+1]) break;
                len[i]++;
            }
            continue;
        }
        int ed = i + k-1;
        if(p[ed-1]<p[ed]){
            len[i] = len[i-1]+1;
        }
        else len[i] = 1;
    }
  //  f0r(i, n)cout << len[i] << " ";
   // cout << endl;
    int times = 0;
    f0r(i, n -k+1){
        if(len[i] == k){
            times = 1;
            continue;
        }
        if(i == 0){
            ans++;
            continue;
        }
        int last = i +k-1;
        if(p[last]>= seg1.query(i, last) && p[i-1]<= seg2.query(i, last)){
            continue;
        }
        ans++;
    }
    ans += times;
    cout << ans << endl;

}



Measured memory_bytes: 6004