#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

using namespace std;
typedef long long ll;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD>
struct ModInt {
	long long val;
	constexpr ModInt(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) v += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr ModInt operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr ModInt operator + (const ModInt& r) const noexcept { return ModInt(*this) += r; }
	constexpr ModInt operator - (const ModInt& r) const noexcept { return ModInt(*this) -= r; }
	constexpr ModInt operator * (const ModInt& r) const noexcept { return ModInt(*this) *= r; }
	constexpr ModInt operator / (const ModInt& r) const noexcept { return ModInt(*this) /= r; }
	constexpr ModInt& operator += (const ModInt& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr ModInt& operator -= (const ModInt& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr ModInt& operator *= (const ModInt& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr ModInt& operator /= (const ModInt& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const ModInt& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const ModInt& r) const noexcept {
		return this->val != r.val;
	}

	friend ostream& operator << (ostream &os, const ModInt<MOD>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream &is, ModInt<MOD>& x) noexcept {
		return is >> x.val;
	}
	static constexpr ModInt<MOD> modpow(const ModInt<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

template<class T>
vector<T> make_vector(int n, T t) {
	return vector<T>(n, t);
}

template<class ...Ts>
auto make_vector(int n, Ts ... ts) {
	return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
}

const int MOD = 998244353;
using mint = ModInt<MOD>;

ll gcd(ll x, ll y)
{
	if (x == 0) return y;
	if (y == 0) return x;

	ll t;

	while (y != 0)
	{
		t = x % y;
		x = y;
		y = t;
	}
	return x;
}

// スライド最小値
void slide_min(int k, const vector <ll>& a, vector <ll>& b)
{
	const int n = SZ(a);
	vector <int> deq(n);
	b.clear();
	b.resize(n - k + 1);

	int s = 0, t = 0; // デックの先頭と末尾

	for (int i = 0; i < n; i++)
	{
		// デックにiを追加
		while (s < t && a[deq[t - 1]] >= a[i]) t--;
		deq[t++] = i;

		if (i - k + 1 >= 0)
		{
			b[i - k + 1] = a[deq[s]]; // 最小値
									  //			b[i-k+1] = deq[s]; // 最小値の場所
			if (deq[s] == i - k + 1)
			{
				// デックの先頭を取り出す
				s++;
			}
		}
	}
}

// スライド最大値
void slide_max(int k, const vector <ll>& a, vector <ll>& b)
{
	const int n = SZ(a);
	vector <int> deq(n);
	b.clear();
	b.resize(n - k + 1);

	int s = 0, t = 0; // デックの先頭と末尾

	for (int i = 0; i < n; i++)
	{
		// デックにiを追加
		while (s < t && a[deq[t - 1]] <= a[i]) t--;
		deq[t++] = i;

		if (i - k + 1 >= 0)
		{
			b[i - k + 1] = a[deq[s]]; // 最大値
									  //			b[i-k+1] = deq[s]; // 最大値の場所
			if (deq[s] == i - k + 1)
			{
				// デックの先頭を取り出す
				s++;
			}
		}
	}
}


// Union-Find法。無向グラフをつなげる。
void union_init(vector <int>& v, int size)
{
	v.clear();
	for (int i = 0; i<size; i++)
	{
		v.push_back(i);
	}
}

// union_connect後に、union_getすると、vはグループの代表番号が入る。v[n]=t行。
// 
int union_get(vector <int>& v, int n)
{
	int t = n;
	int k;
	while (v[t] != t)
	{
		t = v[t];
	}

	while (v[n] != n)
	{
		k = v[n];
		v[n] = t;
		n = k;
	}
	return n;
}


// ノードaとノードbをつなぐ。
// union_connect後のvには、同じグループに入るノードのうちの1つの番号が入る
bool union_connect(vector <int> & v, int a, int b)
{
	a = union_get(v, a);
	b = union_get(v, b);
	if (a == b)
	{
		return false;
	}

	v[a] = b;
	return true;
}

int main()
{
	int N, K;
	cin >> N >> K;

	vector <ll> p(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> p[i];
	}

	vector <ll> lo;
	vector <ll> hi;

	slide_min(K, p, lo);
	slide_max(K, p, hi);

	vector <bool> isSorted(N-K+1);
	int increase = 0;
	for (int i=1;i<N;++i)
	{
		if (p[i -1 ] < p[i])
		{
			increase++;
		}
		else
		{
			increase = 0;
		}

		if (increase >= K - 1)
		{
			isSorted[i - (K - 1)] = true;
		}
	}

	const int D = N - K + 1;

	vector <int> v;
	union_init(v, D);

	int firstSorted = NG;
	for (int i = 0; i < D; ++i)
	{
		if (isSorted[i])
		{
			if (firstSorted == NG)
			{
				firstSorted = i;
			}
			else
			{
				union_connect(v, i, firstSorted);
			}
		}
	}



	for (int i = 0; i < N-K; ++i)
	{
		if (lo[i] == p[i] && hi[i + 1] == p[i + K])
		{
			union_connect(v, i, i+1);
		}
	}
	
	vector <int> num_nodes(D); //
	for (int i = 0; i<D; i++)
	{
		num_nodes[union_get(v, i)]++;
	}

	int ret = 0;

	for (int i = 0; i<D; i++)
	{
		if (num_nodes[i] >= 1)
		{
			ret++;
		}
	}

	cout << ret << endl;





	
	return 0;
}


Measured memory_bytes: 6768