/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ankur Dua
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

using cd = complex<double>;
using ll = long long;
const double PI = acos(-1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

vector<ll> multiply(vector<ll> const& a, vector<ll> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<ll> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    result.resize(a.size()+b.size());
    return result;
}

using namespace std;
ll tree[3000000];
int N=3000000;
class BIT{
public:
    BIT(){
        for(int i=0;i<N;i++){
            tree[i]=0;
        }
    }
    void add(int i, ll v){
        for(;i<N;i+=i&-i){
            tree[i]+=v;
        }
    }

    ll query(int i){
        ll ans=0;
        for(;i>0;i-=i&-i){
            ans+=tree[i];
        }
        return ans;
    }
};
class BSortingASegment {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int n, k;
        cin>>n>>k;
        vector<int> v(n);
        for(int i=0;i<n;i++){
            cin>>v[i];
            v[i]++;
        }
        ll inv=0;
        int ucs=0;
        BIT b;
        for(int i=0;i<k;i++){
            inv+=b.query(n)-b.query(v[i]);
            b.add(v[i], 1);
        }
        ll ans=0;
        if(inv>0)
            ans++;
        else
            ucs++;
        for(int i=k;i<n;i++){
            // remove i-k;
            ll lastinv=inv;
            bool invc=false;
            inv-=b.query(v[i-k]-1);
            b.add(v[i-k], -1);
            if(lastinv!=inv)
                invc=true;
            lastinv=inv;
            inv+=b.query(n)-b.query(v[i]);
            if(inv!=lastinv)
                invc=true;
            b.add(v[i], 1);
            if(!inv)
                ucs++;
            else if(invc)
                ans++;
        }
        if(ucs)
            ans++;
        cout<<ans<<endl;


	}
};


int main() {
	BSortingASegment solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 24448