#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        x = y;
    }
    inline T queryf(T& x,T& y){
        return min(x,y);
    }

public:
    SegmentTree(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での和を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;  //inf
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
    T query(int a, int b){ return get(a,b,0,0,n); }
    int find(ll x,int k=0){
        if(node[k]<=x)return -1;
        if(k>=n-1)return k-n+1;
        if(node[2*k+1]>x)return find(x,2*k+1);
        else return find(x,2*k+2);
    }
};

template<typename T>
struct SegmentTree2{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        x = y;
    }
    inline T queryf(T& x,T& y){
        return max(x,y);
    }

public:
    SegmentTree2(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree2(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での和を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;  //inf
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
    T query(int a, int b){ return get(a,b,0,0,n); }
    int find(ll x,int k=0){
        if(node[k]<=x)return -1;
        if(k>=n-1)return k-n+1;
        if(node[2*k+1]>x)return find(x,2*k+1);
        else return find(x,2*k+2);
    }
};

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n+1);
  vector<int> inc(n+1);
  rep(i,n) cin >> p[i];
  rep(i,n){
    if(p[i+1]>p[i]){
      inc[i+1]=1;
    }
  }
  rep(i,n){
    if(inc[i+1]!=0){
      inc[i+1] += inc[i];
    }
  }

  SegmentTree<int> sgmi(p,inf);
  SegmentTree2<int> sgma(p,0);

  int ans = n-k+1;
  int cnt = 0;
  REP(i,k-1,n){
    if(i==k-1){
      if(inc[i]>=k-1){cnt++;}
      continue;
    }
    if(p[i-k]==sgmi.get(i-k,i) && p[i]>sgma.get(i-k,i)){
      ans--;
    }else if(inc[i]>=k-1){
      cnt++;
    }
  }
  if(cnt>1){
    ans -= cnt-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5888