//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Monoid>
struct SegmentTree
{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
    {
        sz = 1;
        while (sz < n)
            sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x)
    {
        seg[k + sz] = x;
    }

    void build()
    {
        for (int k = sz - 1; k > 0; k--)
        {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x)
    {
        k += sz;
        seg[k] = x;
        while (k >>= 1)
        {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b)
    {
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
        {
            if (a & 1)
                L = f(L, seg[a++]);
            if (b & 1)
                R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const
    {
        return seg[k + sz];
    }
};

class UnionFind
{
    vector<int> par;

public:
    UnionFind(int n) : par(n, -1) {}

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    inline bool same(int u, int v)
    {
        return root(u) == root(v);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) { return -par[root(x)]; }
};

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, k;
    cin >> n >> k;
    SegmentTree<int> seg1(n, [](int a, int b) { return min(a, b); }, INT_MAX);
    SegmentTree<int> seg2(n, [](int a, int b) { return max(a, b); }, INT_MIN);
    akari<int> ps(n), cmp(n + 1);
    for (int i = 0; i < n; i++)
    {
        cin >> ps[i];
        seg1.update(i, ps[i]);
        seg2.update(i, ps[i]);
    }
    for (int i = 1; i < n; i++)
    {
        cmp[i] = cmp[i - 1] + (ps[i - 1] < ps[i]);
    }
    seg1.build();
    seg2.build();
    UnionFind uf(n + 1);
    for (int i = 0; i + k <= n; i++)
    {
        //print(seg1.query(i - 1, i + k - 1), ps[i - 1]);
        //print(seg2.query(i, i + k), ps[i + k - 1]);
        if (cmp[i + k - 1] - cmp[i] == k - 1)
        {
            uf.merge(i, n);
        }
        if (i && seg1.query(i - 1, i + k) == ps[i - 1] && seg2.query(i - 1, i + k) == ps[i + k - 1])
        {
            uf.merge(i - 1, i);
        }
    }
    set<int> s;
    for (int i = 0; i + k <= n; i++)
    {
        // if (s.find(uf.root(i)) == s.end())
        // {
        //     print(uf.root(i));
        // }
        s.insert(uf.root(i));
    }
    cout << s.size() << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 16128