#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define what prev
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123; 

int n, k;
int a[N];
int pref[N];
int ans[N];
int t[N * 4];
int t1[N * 4];
int t_min[N * 4], t_max[N * 4];
int res;
vector <pair <pair <int, int>, int> > g[N];

void Update(int pos, int val, int tl = 1, int tr = n, int v = 1)
{
	if(tl == tr)
	{	
		t[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) Update(pos, val, tl, tm, v + v);
	else Update(pos, val, tm + 1, tr, v + v + 1);
	t[v] = max(t[v + v], t[v + v + 1]);
}

int Get(int l, int r, int tl = 1, int tr = n, int v = 1)
{
	if(tl > r || l > tr) return 0;
	if(l <= tl && tr <= r) return t[v];
	int tm = (tl + tr) / 2;
	return max(Get(l, r, tl, tm, v + v), Get(l, r, tm + 1, tr, v + v + 1));
}

void Update1(int pos, int val, int tl = 1, int tr = n, int v = 1)
{
	if(tl == tr)
	{
		t1[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) Update1(pos, val, tl, tm, v + v);
	else Update1(pos, val, tm + 1, tr, v + v + 1);
	t1[v] = max(t1[v + v], t1[v + v + 1]);
}

int Get1(int l, int r, int tl = 1, int tr = n, int v = 1)
{
	if(tl > r || l > tr) return 0;
	if(l <= tl && tr <= r) return t1[v];
	int tm = (tl + tr) / 2;
	return max(Get1(l, r, tl, tm, v + v), Get1(l, r, tm + 1, tr, v + v + 1)); 
}

void Update_M(int pos, int val, int tl = 1, int tr = n, int v = 1)
{
	if(tl == tr)
	{
		t_min[v] = val;
		t_max[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) Update_M(pos, val, tl, tm, v + v);
	else Update_M(pos, val, tm + 1, tr, v + v + 1);
	t_min[v] = min(t_min[v + v], t_min[v + v + 1]);
	t_max[v] = max(t_max[v + v], t_max[v + v + 1]);
}

int Min(int l, int r, int tl = 1, int tr = n, int v = 1)
{                               
	if(tl > r || l > tr) return mod;
	if(l <= tl && tr <= r) return t_min[v];
	int tm = (tl + tr) / 2;
	return min(Min(l, r, tl, tm, v + v), Min(l, r, tm + 1, tr, v + v + 1)); 
}

int Max(int l, int r, int tl = 1, int tr = n, int v = 1)
{
	if(tl > r || l > tr) return -mod;
	if(l <= tl && tr <= r) return t_max[v];
	int tm = (tl + tr) / 2;
	return max(Max(l, r, tl, tm, v + v), Max(l, r, tm + 1, tr, v + v + 1)); 
}

set <int> s;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
//		freopen("fast.txt", "w", stdout);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i]++;
	for(int i = 1; i <= n; i++)
	{
		pref[i] = Get(a[i] + 1, n);
		Update(a[i], i);
	}	
	for(int i = 1; i <= n - k + 1; i++)
	{
		int l, r;
		l = i, r = i + k - 1;
		g[r].pb(mp(mp(l, 0), i));
	}
	for(int i = 1; i <= n; i++)
	{
		if(pref[i]) Update1(pref[i], a[i] + a[pref[i]]);
		for(auto to : g[i])
		{
			if(Get1(to.F.F, i) <= to.F.S) ans[to.S] = 1;
			else ans[to.S] = 0;		
		}
	}
	for(int i = 1; i <= n; i++) Update_M(i, a[i]);
	int ok = 0;
	for(int i = 1; i <= n - k; i++)
	{
		if(i == 1)
		{
			if(ans[i] || ans[i + 1]) ok = 1;
			if(a[i] == Min(i, i + k) && a[i + k] == Max(i, i + k) && !ans[i] && !ans[i + 1]) s.insert(i + 1);
			else 
			{
				if(!ans[i]) s.insert(i);                                                            
				if(!ans[i + 1]) s.insert(i + 1);
				if(ans[i]) ok = 1;
				if(ans[i + 1]) ok = 1;
			}
		}
		else
		{
			if(ans[i + 1]) continue;	
			if(a[i] == Min(i, i + k) && a[i + k] == Max(i, i + k));
			else s.insert(i + 1);
		}
//		cout << i << ' ' << sz(s) << endl;
	}
	if(n == k) cout << 1 << endl, exit(0);
	if(!ok) for(int i = 1; i <= n - k + 1; i++) ok |= ans[i];
	cout << sz(s) + ok << endl;
}                                


Measured memory_bytes: 35456