#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <functional>
template<typename T>
class SegmentTreeOneAll {
    using Func = function<T(T, T)>;

public:
    vector<T> data;
    int n;
    T init;
    Func update_func;
    Func query_func;
    SegmentTreeOneAll(int _n, T _init, Func up, Func qu) {
        init = _init;
        update_func = up;
        query_func = qu;
        for (n = 1; n < _n; n *= 2)
            ;
        data.resize(2 * n - 1, init);
    }
    void update(int pos, T val) {
        pos += n - 1;
        data[pos] = update_func(data[pos], val);
        while (pos > 0) {
            pos = (pos - 1) / 2;
            data[pos] = query_func(data[2 * pos + 1], data[2 * pos + 2]);
        }
    }
    T query(int l, int r) {
        T res = init;
        for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) {
            if (!(l & 1)) {
                res = query_func(res, data[l]);
            }
            if (!(r & 1)) {
                res = query_func(res, data[r - 1]);
            }
        }
        return res;
    }
};

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    const int inf = 1LL << 29;
    auto MAX = [&](int a, int b) {
        return max(a, b);
    };
    auto MIN = [&](int a, int b) {
        return min(a, b);
    };
    SegmentTreeOneAll<int> seg1(n, inf, MIN, MIN), seg2(n, -1, MAX, MAX);
    vector<int> P(n);
    REP(i, 0, n) {
        cin >> P[i];
        seg1.update(i, P[i]);
        seg2.update(i, P[i]);
    }

    UnionFind uf(n - k + 1);

    REP(i, 0, n - k) {
        if (seg1.query(i, i + k) == P[i] && seg2.query(i, i + k) < P[i + k]) {
            uf.Union(i, i + 1);
        }
    }

    vector<int> sum(n, 0);
    REP (i, 0, n - 1) {
        sum[i + 1] = sum[i] + (P[i] < P[i + 1]);
    }
    int prev = -1;
    REP (i, 0, n - k + 1) {
        if (sum[i + k - 1] - sum[i] == k - 1) {
            if (prev != -1) {
                uf.Union(prev, i);
            }
            prev = i;
        }

    }

    cout << uf.size() << endl;

    return 0;
}


Measured memory_bytes: 6784