#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

class UnionFind {
    vector<int> parent;
    vector<int> rank;

    int root(int x) {
        return parent[x] >= 0 ? parent[x] = root(parent[x]) : x;
    }

public:
    void unite(int x, int y) {
        int root_x = root(x);
        int root_y = root(y);
        if (root_x == root_y)
            return;

        if (rank[root_x] > rank[root_y]) {
            parent[root_x] += parent[root_y];
            parent[root_y] = root_x;
        } else {
            if (rank[root_x] == rank[root_y])
                ++rank[root_y];

            parent[root_y] += parent[root_x];
            parent[root_x] = root_y;
        }
    }

    bool is_same(int x, int y) {
        return root(x) == root(y);
    }

    int group_size(int x) {
        return -parent[root(x)];
    }

    int num_groups() {
        int num = 0;
        for (int k : parent) {
            num += k < 0;
        }
        return num;
    }

    UnionFind(int n) : parent(n, -1), rank(n, 1) {}
};

#include <algorithm>
#include <array>
#include <functional>

// Nは2べき！！！！！！！！
template <typename T = int, int N = 1 << 17>
class SegmentTree {
    // 単位元
    const T e;
    std::array<T, 2 * N - 1> tree;
    std::function<T(T, T)> op;

    T _query(int l, int r, int i, int ln, int rn) const {
        if (r <= ln || rn <= l) return e;
        if (l <= ln && rn <= r) return tree[i];
        int center = (ln + rn) / 2;
        T vl = _query(l, r, 2 * i + 1, ln, center);
        T vr = _query(l, r, 2 * i + 2, center, rn);
        return op(vl, vr);
    }
public:
    T operator[](int i) const {
        return tree[i + N - 1];
    }

    void update(int i, T x) {
        tree[i += N - 1] = x;
        // 節点iの子のindexは2 * i + 1, 2 * i + 2
        while (i > 0) {
            i = (i - 1) / 2;
            tree[i] = op(tree[2 * i + 1], tree[2 * i + 2]);
        }
    }
    // [l, r)
    T query(int l, int r) const {
        return _query(l, r, 0, 0, N);
    }

    SegmentTree(T e, std::function<T(T, T)> op) : e(e), op(op) {
        std::fill(tree.begin(), tree.end(), e);
    }
};

// 単位元
template<typename T>
struct InitVal {
    static const T RangeSum;
    static const T RangeMin;
    static const T RangeMax;
};
template<> const int InitVal<int>::RangeSum = 0;
template<> const int InitVal<int>::RangeMin = 1000000007;
template<> const int InitVal<int>::RangeMax = -1000000007;
template<> const long long InitVal<long long>::RangeSum = 0LL;
template<> const long long InitVal<long long>::RangeMin = 1000000000000000007LL;
template<> const long long InitVal<long long>::RangeMax = -1000000000000000007LL;

template<typename T = int, int N = 1 << 17>
inline SegmentTree<T, N> make_sum_segtree() {
    return SegmentTree<T, N>(InitVal<T>::RangeSum, [](T a, T b) { return a + b; });
}

template<typename T = int, int N = 1 << 17>
inline SegmentTree<T, N> make_min_segtree() {
    return SegmentTree<T, N>(InitVal<T>::RangeMin, [](T a, T b) { return std::min(a, b); });
}

template<typename T = int, int N = 1 << 17>
inline SegmentTree<T, N> make_max_segtree() {
    return SegmentTree<T, N>(InitVal<T>::RangeMax, [](T a, T b) { return std::max(a, b); });
}

int main() {
    int n, k; cin >> n >> k;
    vector<int> p(n + 2);
    p.front() = -inf;
    p.back() = -inf;
    auto st_max = make_max_segtree<int, 1 << 18>();
    auto st_min = make_min_segtree<int, 1 << 18>();
    for (int i = 0; i < n; ++i) {
        int _p; cin >> _p;
        p[i + 1] = _p;
        st_max.update(i, _p);
        st_min.update(i, _p);
    }

    UnionFind uf(n - k + 1);
    for (int i = 0; i < n - k; ++i) {
        if (st_min.query(i, i + k + 1) == st_min[i] && st_max.query(i, i + k + 1) == st_max[i + k])
            uf.unite(i, i + 1);
    }

    int s = 1;
    vector<int> t;
    for (int i = 1; i <= n + 1; ++i) {
        if (p[i - 1] > p[i]) {
            if (i - s >= k) t.push_back(s - 1);
            s = i;
        }
    }

    for (int i = 1; i < t.size(); ++i) {
        uf.unite(t[i - 1], t[i]);
    }

    cout << uf.num_groups() << endl;
    return 0;
}

Measured memory_bytes: 6784