#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

struct SegmentTreemin {
    int n;
    vector<int> node;

    SegmentTreemin(vector<int> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n*=2;
        node.resize(2*n-1, INF);
        
        REP(i,0,sz) node[i+n-1] = v[i];
        REPR(i,n-2,-1) node[i] = min(node[2*i+1], node[2*i+2]);
    }

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

    int getmin(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 = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

struct SegmentTreemax {
    int n;
    vector<int> node;

    SegmentTreemax(vector<int> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n*=2;
        node.resize(2*n-1, 0);
        
        REP(i,0,sz) node[i+n-1] = v[i];
        REPR(i,n-2,-1) node[i] = max(node[2*i+1], node[2*i+2]);
    }

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

    int getmax(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 = getmax(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,k,same=0,shojunk=0,shojunkp1=0;
    cin>>n>>k;
    Vi p(n);
    REP(i,0,n) cin>>p[i];

    SegmentTreemin segmin(p);
    SegmentTreemax segmax(p);

    Vi rui(n,0);
    REP(i,1,n){
        if(p[i]>p[i-1]) rui[i]=1;
    }
    accum(rui);
    REP(i,0,n-k+1){
        if(rui[i+k-1]-rui[i]==k-1) shojunk++;
//        cout<<same<<endl;
    }
    if(shojunk==n-k+1){cout<<1<<endl;return 0;}

    k++;
    REP(i,0,n-k+1){
        if(rui[i+k-1]-rui[i]==k-1) shojunkp1++;
    }
    REP(i,0,n-k+1){
        if(p[i]==segmin.getmin(i,i+k) && p[i+k-1]==segmax.getmax(i,i+k)) same++;
//        cout<<segmin.getmin(i,i+k)<<" "<<segmax.getmax(i,i+k)<<endl;
    }
    k--;

    cout<<(n-k+1)-(same-shojunkp1)-(max(0LL,shojunk-1))<<endl;
//    cout<<same<<" "<<shojunkp1<<" "<<shojunk<<endl;
    return 0;
}


Measured memory_bytes: 11620