#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
struct SegmentTreemin
{
private:
     int N;
     vector<int> node;

public:
     SegmentTreemin(vector<int> v){
         int si=v.size();
         N=1;
         while (N<si){
             N*=2;
         }
         node.resize(2*N-1,inf);
         for(int i=0;i<si;i++)node[i+N-1]=v[i];
         for(int i=N-2;i>=0;i--)node[i]=min(node[2*i+1],node[2*i+2]);
     }

    void update(int x,int val){
        x+=N-1;
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=min(node[2*x+1],node[2*x+2]);
        }
    }

//[a,b)の最小値を答える
//k:自分が今いるノードのインデックス
    int getval(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=N;
        if(r<=a||b<=l)return inf;
        if(a<=l && r<=b)return node[k];

        int vl=getval(a,b,2*k+1,l,(l+r)/2);
        int vr=getval(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

struct SegmentTreemax
{
private:
     int N;
     vector<int> node;

public:
     SegmentTreemax(vector<int> v){
         int si=v.size();
         N=1;
         while (N<si){
             N*=2;
         }
         node.resize(2*N-1,0);
         for(int i=0;i<si;i++)node[i+N-1]=v[i];
         for(int i=N-2;i>=0;i--)node[i]=max(node[2*i+1],node[2*i+2]);
     }

    void update(int x,int val){
        x+=N-1;
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=max(node[2*x+1],node[2*x+2]);
        }
    }

//[a,b)の最大値を答える
//k:自分が今いるノードのインデックス
    int getval(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=N;
        if(r<=a||b<=l)return 0;
        if(a<=l && r<=b)return node[k];

        int vl=getval(a,b,2*k+1,l,(l+r)/2);
        int vr=getval(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};

int main(){cout<<fixed<<setprecision(20);
		   int n,k;
           cin>>n>>k;
           vin p(n+1);
           rep(i,0,n)cin>>p[i];
           p[n+1]=inf;
           SegmentTreemin segmin(p);
           SegmentTreemax segmax(p);
           int ans=0;
           /////////////
           int cnt=0;
           vector<bool> ng(n,false);
           rep(i,0,n-1){
             if(p[i]<p[i+1])cnt++;
             else cnt=0;
            if(cnt>=k-1){
              ng[i-k+2]=true;
             }
           }
           /////////////
           bool q=false;
           rep(i,0,n-k+1){
             if(p[i]<segmin.getval(i+1,i+k) && p[i+k]>segmax.getval(i+1,i+k)){
             }
             else {
               if(ng[i]){
                 if(q)continue;
                 q=true;
               }
               ans++;
             }
           }
           cout<<ans<<endl;
               
}

Measured memory_bytes: 8892