#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct SegmentTree1{
    int n;
    vector<ll> node;
    
    ll calc(ll a,ll b) {
        return min(a,b);
    }
    ll e=LINF;
    
    SegmentTree1(vector<ll> v) {
        int sz=v.size();
        n=1;
        while(n<sz) {
            n*=2;
        }
        node.resize(2*n-1,e);
        for(int i=0;i<sz;i++) {
            node[i+n-1]=v[i];
        }
        for(int i=n-2;i>=0;i--) {
            node[i]=calc(node[2*i+1],node[2*i+2]);
        }
    }
    
    void update(int x,ll val) {
        x=n+x-1;
        node[x]=val;
        while(x>0) {
            x=(x-1)/2;
            node[x]=calc(node[2*x+1],node[2*x+2]);
        }
    }
    
    ll query(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;
        if(a<=l && r<=b) return node[k];
        
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        
        return calc(vl,vr);
    }
    
    ll at(int x) {
        return node[n+x-1];
    }
};

struct SegmentTree2{
    int n;
    vector<ll> node;
    
    ll calc(ll a,ll b) {
        return max(a,b);
    }
    ll e=-1;
    
    SegmentTree2(vector<ll> v) {
        int sz=v.size();
        n=1;
        while(n<sz) {
            n*=2;
        }
        node.resize(2*n-1,e);
        for(int i=0;i<sz;i++) {
            node[i+n-1]=v[i];
        }
        for(int i=n-2;i>=0;i--) {
            node[i]=calc(node[2*i+1],node[2*i+2]);
        }
    }
    
    void update(int x,ll val) {
        x=n+x-1;
        node[x]=val;
        while(x>0) {
            x=(x-1)/2;
            node[x]=calc(node[2*x+1],node[2*x+2]);
        }
    }
    
    ll query(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;
        if(a<=l && r<=b) return node[k];
        
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        
        return calc(vl,vr);
    }
    
    ll at(int x) {
        return node[n+x-1];
    }
};

struct UnionFind {
    vector<ll> data;
    UnionFind(int size): data(size,-1) {
    }
    
    int root(int x){
        return (data[x] < 0)? x : data[x]=root( data[x] );
    }
    
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if( x != y ){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    
    bool find(int x, int y){
        return root(x) == root(y);
    }
    
    int size(int x){
        return -data[ root(x) ];
    }
};

int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    UnionFind uf(n);
    SegmentTree1 MIN(p);
    SegmentTree2 MAX(p);
    
    vector<int> sorted;
    int cnt=1;
    rep(i,n-1) {
        if(p[i]<p[i+1]) cnt++;
        else cnt=1;
        
        if(cnt>=k) sorted.push_back(i-(k-2));
    }
    
    if(sz(sorted)>1) {
        rep(i,sz(sorted)-1) uf.unite(sorted[i],sorted[i+1]);
    }
    
    rep(i,n-k) {
        if(p[i]<MIN.query(i+1,i+k) && MAX.query(i+1,i+k)<p[i+k]) {
            uf.unite(i,i+1);
        }
    }
    
    set<int> st;
    rep(i,n-k+1) st.insert(uf.root(i));
    //for(int x:st) cout<<x<<endl;
    cout<<sz(st)<<endl;
}


Measured memory_bytes: 20964