#include<bits/stdc++.h>
#include<chrono>
#include<random>
using namespace std;
using namespace chrono;
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef vector<string> vs;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
	out << "(" << P.first << ", " << P.second << ")";
	return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
mt19937 rnd(time(0));

template<class T, class BO>
struct fastseg{
	int n;
	vector<T> arr;
	BO bin_op;
	T id;
	fastseg(const vector<T> &_arr, BO _bin_op, const T &_id): n(_arr.size()), bin_op(_bin_op), id(_id), arr(n << 1, _id){
		for(int i = 0; i < n; i ++) arr[i + n] = _arr[i];
		build();
	}
	void build(){
		for(int i = n - 1; i > 0; i --){
			arr[i] = bin_op(arr[i << 1], arr[i << 1 | 1]);
		}
	}
	void update(int p, T val){
		for(arr[p += n] = val; p > 1; p >>= 1){
			arr[p >> 1] = bin_op(arr[p], arr[p ^ 1]);
		}
	}
	T query(int l, int r){
		if(l >= r){
			return id;
		}
		T resl = id, resr = id;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1) resl = bin_op(resl, arr[l ++]);
			if(r & 1) resr = bin_op(arr[-- r], resr);
		}
		return bin_op(resl, resr);
	}
	void clear(){
		fill(arr.begin(), arr.end(), id);
	}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vi a(n);
	cin >> a;
	fastseg<int, function<int(int, int)>> min_tr(a, [](int x, int y){return min(x, y);}, int(2e9));
	fastseg<int, function<int(int, int)>> max_tr(a, [](int x, int y){return max(x, y);}, 0);
	vi b(n);
	for(int i = 1; i < n; i ++){
		if(a[i - 1] > a[i]){
			b[i] = b[i - 1] + 1;
		}
		else{
			b[i] = b[i - 1];
		}
	}
	vi q;
	bool found = false;
	for(int i = 0; i + k <= n; i ++){
		if(b[i] != b[i + k - 1]){
			q.push_back(i);
		}
		else{
			found = true;
		}
	}
	int res = found + !q.empty();
	for(int i = 1; i < q.size(); i ++){
		int u = q[i - 1], v = q[i];
		if(v - u >= k || b[v - 1] != b[u] || b[v + k - 1] != b[u + k] || a[v - 1] > min_tr.query(v, u + k) || a[u + k] < max_tr.query(v, u + k)){
			res ++;
		}
	}
	cout << res;
	return 0;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                  //
//                                                                                                  //
//                                              _____________                                       //
//             ++++++++++                ___------------------\\\\                                  //
//           +++`+``+`+`++++        ///`````````````````````````````\\\                             //
//           ++`+`+``+++`++++  /////```````````````````````````````````\\                           //
//           +++`++`+`+``+++/////`````````````````````````````````````````\\                        //
//             +++`++`+``+///```````````|```````````````````````````````````\\                      //
//          ____++++/++++/`````````````/````````|````````|```````````````````\\                     //
//        /  /  / |    //``````````````|````````|```````|````````|````````````\\                    //
//       /  /  /  | ///````````/```````|```````||```````|````````|``````\```````\\                  //
//       | /  /   |///`````````|``````/````````|````````|````````|```````|```````\\                 //
//       |/   |   |//``|```````|``````|````````|`````````|```````|```````|````````\\                //
//       /\___|__//`|``|```````|`    |      ``:|````````|:```````|```````|```|`````|                //
//      /     /  /``|``|``````|/     |        :|     ```:|```````|```````|``++````++                //
//     /     / //```|``|``````|      |        |:        :|    ```|```````|```++``++`\               //
//     |    /  /````|``|``````/    _.::::.    |          |      |    ````|```|`++`\`|               //
//     |   /   |````|``|`````|            `                    |       ``|```++``++`|               //
//     |  /    |````|``|`````|                                 :         |``++````++|               //
//     | /     /````|``|`````|                              _.-:::.      |..`|``.`|.|               //
//     |/     /`````|``|`````|                                     `     |```|````|`|               //
//    /|      |`````|``|`````|                    :'                    .|```|````|.|               //
//   / |      |`````|``|`````|                                         /|-|``|````|`|               //
//  /  |      |`````|```\````|                                        / ||```|````|``\              //
// /   |      |`````|````|```|::                                    /_| ||```|````|``|              //
//            |`````|````|```|:|:.        `.._                    .\___/:|```|````|``|              //
//            |`````\````|```|:|::-          ``:::....           -:|:|:::|```|````|``|              //
//            |``````|```|```|:|::`|.                          .:::|:|:::|```|````|``|              //
//             \`````|```|```|:|::/|--.                     .`:|:::|:|:::/```|````|``|              //
//              |````|```|```\:|:|:|-----             _..-:|:|:|:::|:|::|````|````|`/               //
//              |````|```|````\|:|:|-------.____.....------|/::|:::|:|::|````|````|`|               //
//              |````|```|\````\:|/\___________    ________/\--\:::|:|::|````/````|`|               //
//              |````\```| \```|:/-------------\  /----------\``\::|:|::|```/`````|`|               //
//              |`````|``|  \``|/---------------\/------------\_________|```|`````|`|               //
//                                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                  //
//                                        Created by Aeren                                          //
//                                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 6136