#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <array>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using Int = long long int;
using Real = long double;
using std::array;
using std::pair;
using std::string;
using std::tuple;
using std::vector;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = vector<vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
constexpr int INF = std::numeric_limits<int>::max() / 3;
// constexpr Int MOD = 1000000007;
// const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

struct MaxSegmentTree {
    int length;
    std::vector<int> dat;

    int query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return -INF;
        if (ql <= nl && nr <= qr) return dat[nidx];
        int vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        int vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return std::max(vl, vr);
    }

    MaxSegmentTree(int N) : length(1) {
        while (length < N) length <<= 1;
        dat.assign(length * 2, 0);
    }

    // half-open interval [ql, qr)
    int query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, int e) {
        int nidx = idx + length;
        dat[nidx] = e;
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = std::max(dat[nidx * 2], dat[nidx * 2 + 1]);
        }
    }
};

struct MinSegmentTree {
    int length;
    std::vector<int> dat;

    int query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return INF;
        if (ql <= nl && nr <= qr) return dat[nidx];
        int vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        int vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return std::min(vl, vr);
    }

    MinSegmentTree(int N) : length(1) {
        while (length < N) length <<= 1;
        dat.assign(length * 2, 0);
    }

    // half-open interval [ql, qr)
    int query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, int e) {
        int nidx = idx + length;
        dat[nidx] = e;
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = std::min(dat[nidx * 2], dat[nidx * 2 + 1]);
        }
    }
};

struct UnionFind {
    vector<int> par, num;
    int gnum;

    UnionFind(int N) : par(N), num(N, 1), gnum(N) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (num[u] < num[v]) std::swap(u, v);
        num[u] += num[v];
        par[v] = u;
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return num[find(v)]; }
};

int main() {
    int n, k;
    std::cin >> n >> k;

    MaxSegmentTree maxseg(n);
    MinSegmentTree minseg(n);
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> p[i];
        maxseg.update(i, p[i]);
        minseg.update(i, p[i]);
    }

    vector<int> sorted;
    for (int i = 0; i < n - k + 1;) {
        bool judge = true;
        for (int j = 0; j < k - 1; ++j) {
            if (p[i + j] > p[i + j + 1]) {
                judge = false;
                i = i + j + 1;
                break;
            }
        }
        if (judge) {
            sorted.push_back(i);
            i += k;
        }
    }

    UnionFind uf(n - k + 1);
    for (int i = 0; i + 1 < sorted.size(); ++i) {
        uf.unite(sorted[i], sorted[i + 1]);
    }

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

    std::set<int> pars;
    for (int i = 0; i < n - k + 1; ++i) {
        pars.insert(uf.find(i));
    }

    std::cout << pars.size() << std::endl;
    return 0;
}


Measured memory_bytes: 16128