#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

struct UnionFind
{
    std::vector<std::size_t> _par;
    std::vector<std::size_t> _size;
    std::vector<std::size_t> _rank;

    UnionFind(std::size_t N)
        : _par(N)
        , _size(N, 1)
        , _rank(N, 0)
    {
        for (std::size_t i = 0; i < N; i++)
        {
            _par[i] = i;
        }
    }

    std::size_t Root(std::size_t x)
    {
        if (_par[x] == x)
        {
            return x;
        }
        return _par[x] = Root(_par[x]);
    }

    void Unite(std::size_t x, std::size_t y)
    {
        auto rx = Root(x);
        auto ry = Root(y);
        if (rx != ry)
        {
            if (_rank[rx] < _rank[ry])
            {
                _par[rx] = ry;
                _size[ry] += _size[rx];
            }
            else
            {
                _par[ry] = rx;
                _size[rx] += _size[ry];
                if (_rank[rx] == _rank[ry])
                {
                    _rank[ry]++;
                }
            }
        }
    }

    size_t Size(std::size_t x) { return _size[Root(x)]; }

    bool Same(std::size_t x, std::size_t y)
    {
        auto rx = Root(x);
        auto ry = Root(y);
        return rx == ry;
    }
};

class MinMaxSet
{
public:
    MinMaxSet(int n) { removed.resize(n, false); }

    void push(int v)
    {
        mins.push(v);
        maxs.push(v);
    }

    int min()
    {
        if (mins.empty())
        {
            return -10000000;
        }
        while (!mins.empty())
        {
            if (removed[mins.top()])
            {
                mins.pop();
            }
            else
            {
                break;
            }
        }
        return mins.top();
    }

    int max()
    {
        if (maxs.empty())
        {
            return 10000000;
        }
        while (!maxs.empty())
        {
            if (removed[maxs.top()])
            {
                maxs.pop();
            }
            else
            {
                break;
            }
        }
        return maxs.top();
    }

    void remove(int v) { removed[v] = true; }

private:
    priority_queue<int, vector<int>, greater<>> mins;
    priority_queue<int> maxs;
    vector<bool> removed;
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> vs(n);
    for (auto& v : vs)
    {
        cin >> v;
    }

    MinMaxSet s(n);
    for (int i = 0; i < k; i++)
    {
        s.push(vs[i]);
    }

    UnionFind uf(n);

    for (int i = k; i < n; i++)
    {
        s.remove(vs[i - k]);

        if (vs[i - k] < s.min() && s.max() < vs[i])
        {
            uf.Unite(i - k, i - k + 1);
        }
        s.push(vs[i]);
    }

    int prev = -100;
    int first = -1;
    int seqlen = 0;
    for (int i = 0; i < n; i++)
    {
        if (prev < vs[i])
        {
            seqlen++;
            if (seqlen == k)
            {
                if (first == -1)
                {
                    first = i - k + 1;
                }
                uf.Unite(first, i - k + 1);
                seqlen = k - 1;
            }
        }
        else
        {
            seqlen = 1;
        }
        prev = vs[i];
    }

    set<int> ans_set;
    for (int i = 0; i < n - k + 1; i++)
    {
        ans_set.insert(uf.Root(i));
    }
    cout << ans_set.size() << endl;
}

Measured memory_bytes: 16660