#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;


struct SegTree {
    const int MINUS_INF = numeric_limits<int>::min();
    int n;
    vector<int> t;
    SegTree(int nn = 0) {
        n = nn;
        t.assign(4 * n + 10, 0);
    }
    int build(int v, int tl, int tr, const vector<int>& a) {
        if (tl == tr)
            return t[v] = a[tl];
        int mid = (tl + tr) / 2;
        return t[v] = max(build(2 * v, tl, mid, a), build(2 * v + 1, mid + 1, tr, a));
    }
    void build(const vector<int>& in) {
        n = in.size();
        t.assign(4 * n + 10, 0);
        build(1, 0, n - 1, in);
    }
    int getMax(int v, int tl, int tr, int l, int r) {
        if (l > r)
            return MINUS_INF;
        if (l == tl && r == tr)
            return t[v];
        int tm = (tl + tr) / 2;
        return max(getMax(v * 2, tl, tm, l, min(r, tm)), getMax(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
    }
    int getMax(int l, int r) {
        return getMax(1, 0, n - 1, l, r);
    }
    void update(int v, int tl, int tr, int pos, int new_val) {
        if (tl == tr) {
            t[v] = new_val;
        }
        else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                update(v * 2, tl, tm, pos, new_val);
            else
                update(v * 2 + 1, tm + 1, tr, pos, new_val);
            t[v] = max(t[v * 2], t[v * 2 + 1]);
        }
    }
    void update(int pos, int new_val) {
        update(1, 0, n - 1, pos, new_val);
    }
};


void solve() {
    int n, k;
    cin >> n >> k;
    int res = 0;
    vector<int> p(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i];

    vector<bool> srt(n - k + 1, 0);
    int c = 0;
    int r = 0;
    for (int i = 0; i < srt.size(); ++i) {
        r = max(r, i + 1);
        while ((r < n) && (p[r] > p[r - 1]))
            ++r;
        srt[i] = (r - i) >= k;
        if (srt[i])
            res = 1;
        //cerr << srt[i] << " ";
    }
    //cerr << endl;
    SegTree t1;
    t1.build(p);
    vector<int> pp(n);
    for (int i = 0; i < n; ++i)
        pp[i] = -p[i];
    SegTree t2;
    t2.build(pp);
    if (srt[0] == 0)
        ++res;
    for (int i = 1; i < n - k + 1; ++i) {
        if (srt[i])
            continue;
        //cerr << res << " ";
        int m1 = t1.getMax(i - 1, i + k - 1);
        int m2 = -t2.getMax(i - 1, i + k - 1);
        if ((p[i - 1] != m2) || (p[i + k - 1] != m1))
            ++res;
        
    }
    cout << res << endl;

}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();

#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

Measured memory_bytes: 8064