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

template<typename Info>
class SegmentTree1 {
private:
	int n;
	vector<Info> tree;
	
	Info merge(Info &l, Info &r) {
		return min(l, r);
	}
	
public:
	SegmentTree1() {}
	SegmentTree1(int k) {
		n = k + 1;
		tree.resize(n << 1);
	}
	SegmentTree1(vector<Info> v) {
		n = (int) v.size();
		tree.resize(n << 1);
		for(int i = 0; i < n; i++) {
			tree[i + n] = v[i];
		}
		for(int i = n - 1; i >= 1; i--) {
			tree[i] = merge(tree[i + i], tree[i + i + 1]);
		}
	}
	
	void init(int k) {
		n = k + 1;
		tree.resize(n << 1);
	}
	
	void up(int pos, Info val) {
		pos += n;
		tree[pos] = val;
		while(pos > 1) {
			pos >>= 1;
			tree[pos] = merge(tree[pos + pos], tree[pos + pos + 1]);
		}
	}
	
	Info get(int l, int r) {
		Info ans = 1e9; //colocar a base
		for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
			if (l & 1) {
				ans = merge(ans, tree[l++]);
			}
			if (r & 1) {
				ans = merge(ans, tree[--r]);
			}
		}
		return ans;
	}
};

template<typename Info>
class SegmentTree2 {
private:
	int n;
	vector<Info> tree;
	
	Info merge(Info &l, Info &r) {
		return max(l, r);
	}
	
public:
	SegmentTree2() {}
	SegmentTree2(int k) {
		n = k + 1;
		tree.resize(n << 1);
	}
	SegmentTree2(vector<Info> v) {
		n = (int) v.size();
		tree.resize(n << 1);
		for(int i = 0; i < n; i++) {
			tree[i + n] = v[i];
		}
		for(int i = n - 1; i >= 1; i--) {
			tree[i] = merge(tree[i + i], tree[i + i + 1]);
		}
	}
	
	void init(int k) {
		n = k + 1;
		tree.resize(n << 1);
	}
	
	void up(int pos, Info val) {
		pos += n;
		tree[pos] = val;
		while(pos > 1) {
			pos >>= 1;
			tree[pos] = merge(tree[pos + pos], tree[pos + pos + 1]);
		}
	}
	
	Info get(int l, int r) {
		Info ans = 0; //colocar a base
		for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
			if (l & 1) {
				ans = merge(ans, tree[l++]);
			}
			if (r & 1) {
				ans = merge(ans, tree[--r]);
			}
		}
		return ans;
	}
};

template<typename Info>
class SegmentTree3 {
private:
	int n;
	vector<Info> tree;
	
	Info merge(Info &l, Info &r) {
		return l + r;
	}
	
public:
	SegmentTree3() {}
	SegmentTree3(int k) {
		n = k + 1;
		tree.resize(n << 1);
	}
	SegmentTree3(vector<Info> v) {
		n = (int) v.size();
		tree.resize(n << 1);
		for(int i = 0; i < n; i++) {
			tree[i + n] = v[i];
		}
		for(int i = n - 1; i >= 1; i--) {
			tree[i] = merge(tree[i + i], tree[i + i + 1]);
		}
	}
	
	void init(int k) {
		n = k + 1;
		tree.resize(n << 1);
	}
	
	void up(int pos, Info val) {
		pos += n;
		tree[pos] = val;
		while(pos > 1) {
			pos >>= 1;
			tree[pos] = merge(tree[pos + pos], tree[pos + pos + 1]);
		}
	}
	
	Info get(int l, int r) {
		Info ans = 0; //colocar a base
		for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
			if (l & 1) {
				ans = merge(ans, tree[l++]);
			}
			if (r & 1) {
				ans = merge(ans, tree[--r]);
			}
		}
		return ans;
	}
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> p(n), magic(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n - 1; i++) {
    magic[i] = p[i] < p[i + 1];
  }
  SegmentTree1<int> seg1(p);
  SegmentTree2<int> seg2(p);
  SegmentTree3<int> seg3(magic);
  int ant = 0;
  int ans = 0;
  int eq = 0;
  for (int l = 0, r = k - 1; r < n; l++, r++) {
    bool cur = 0;
    if (seg3.get(l, r - 1) == k - 1) {
      eq = 1;
      cur = 1;
    }
    if ((seg2.get(l, r) != p[r] || ant == 0) && !cur) {
      ans++;
    }
    ant = (seg1.get(l, r) == p[l]);
    //cout << l << ' ' << r << ' ' << seg1.get(l, r) << ' ' << seg2.get(l, r) << ' ' << seg3.get(l, r - 1) << ' ' << ans << ' ' << eq << endl;
  }
  cout << ans + eq << endl;
  return 0;
}


Measured memory_bytes: 7792