#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "../benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

template<class T> class RMQ{
  vv<T> vals;
public:
  inline T get(int l,int r){//[l,r]
    if(l==r)return vals[0][l];
    const int d=31-__builtin_clz(l^r); //left-most distinct bit
    return max(vals[d][l],vals[d][r]);
  }
  RMQ(vector<T> &v,T e=-MOD){
    int n=v.size();
    int d=1,N=2;
    while(N<n) N*=2, ++d;
    vals.resize(d,vector<T>(N,e));
    rep(i,n) vals[0][i]=v[i];
    reps(i,1,d)rep(j,N){
      const int b=(j>>i|1)<<i;
      vals[i][j]=j>>i&1?get(b,j):get(j,b-1);
    }
  }
};
template<class T> class RmQ{
  vv<T> vals;
public:
  inline T get(int l,int r){//[l,r]
    if(l==r)return vals[0][l];
    const int d=31-__builtin_clz(l^r); //left-most distinct bit
    return min(vals[d][l],vals[d][r]);
  }
  RmQ(vector<T> &v,T e=MOD){
    int n=v.size();
    int d=1,N=2;
    while(N<n) N*=2, ++d;
    vals.resize(d,vector<T>(N,e));
    rep(i,n) vals[0][i]=v[i];
    reps(i,1,d)rep(j,N){
      const int b=(j>>i|1)<<i;
      vals[i][j]=j>>i&1?get(b,j):get(j,b-1);
    }
  }
};

int bf(vector<int> a,int t){
	int n=a.size();
	set<vector<int>> st;
	rep(i,n+1-t){
		auto b=a;
		sort(b.begin()+i,b.begin()+i+t);
		st.emplace(b);
	}
	return st.size();
}

int solve(vector<int> a,int t){
	int n=a.size();
	RMQ<int> mx(a);
	RmQ<int> mn(a);
	int re=n-t+1;
	reps(i,1,n){
		int l=i,r=i+t-2;
		if(r+1>=n) break;
		if(a[l-1]<mn.get(l,r) && mx.get(l,r)<a[r+1]){
			--re;
			// auto b=a, c=a;
			// sort(b.begin()+l-1,b.begin()+r+1);
			// sort(c.begin()+l-1,c.begin()+r+2);
			// assert(b==c);
		}else{
			// auto b=a, c=a;
			// sort(b.begin()+l-1,b.begin()+r+1);
			// sort(c.begin()+l-1,c.begin()+r+2);
			// assert(b!=c);
		}
	}
	out(re,1);
	int cnt=0;
	{
		int inc=0;
		int prv=0;
		reps(i,1,t-1)if(a[i-1]<a[i]) ++inc;
		reps(i,t-1,n){
			if(a[i-1]<a[i]) ++inc;
			if(inc==t-1){
				if(MX(prv,1)) ++cnt;
			}else{
				prv=0;
			}
			if(a[i+1-t]<a[i+2-t]) --inc;
		}
	}
	out(cnt,1);
	re-=max(0,cnt-1);
	out(re,1);
	return re;
}


int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	// solve({3,4,1,2,0},2); return 0;
	if(0)rep(_,100){
		int n=100;
		reps(t,2,n+1){
			vector<int> a(n); iota(all(a),0);
			random_shuffle(all(a));
			int ans=bf(a,t);
			int re=solve(a,t);
			if(ans!=re){
				out(a,t,ans,re,1);
				return 1;
			}
		}
	}
	int n,t;
	cin>>n>>t;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	cout<<solve(a,t)<<endl;
  return 0;
}


Measured memory_bytes: 39804