#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cerr << v[i] << " \n"[i == sz - 1];
    }
}

class UnionFind
{
    std::vector<int> data;

public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

struct RangeMinimumQuery
{
    using type = int;
    static type id() { return INT_MAX; }
    static type op(const type &l, const type &r) { return std::min(l, r); }
};

struct RangeMaximumQuery
{
    using type = int;
    static type id() { return -INT_MAX; }
    static type op(const type &l, const type &r) { return std::max(l, r); }
};

template <typename M>
class SegmentTree
{
    using T = typename M::type;
    int n;
    std::vector<T> node;

public:
    // v を基に初期化
    SegmentTree(const std::vector<T> &v)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < int(v.size()))
            n *= 2;
        node.resize(2 * n, M::id());

        // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
        for (int i = 0; i < int(v.size()); i++)
            node[i + n] = v[i];
        for (int i = n - 1; i >= 0; i--)
            node[i] = M::op(node[2 * i], node[2 * i + 1]);
    }
    // Monoid::id 初期化
    SegmentTree(int _n)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < _n)
            n *= 2;
        node.resize(2 * n, M::id());
    }
    // x 番目を val に更新
    void update(int x, T val)
    {
        x += n;
        node[x] = val;
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // v[x] を M::op(v[x], val) に更新
    void operation(int x, T val)
    {
        x += n;
        node[x] = M::op(node[x], val);
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // [a, b) の op
    T query(int l, int r)
    {
        l += n;
        r += n;
        T retl = M::id(), retr = M::id();
        while (l < r)
        {
            if (l & 1)
                retl = M::op(retl, node[l++]);
            if (r & 1)
                retr = M::op(node[--r], retr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(retl, retr);
    }
};

SegmentTree<RangeMinimumQuery> mi(200010);
SegmentTree<RangeMaximumQuery> ma(200010);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    UnionFind uf(n - k + 1);
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        mi.update(i, p[i]);
        ma.update(i, p[i]);
    }
    assert(k != 1);
    vector<int> cnt(n, 1);
    for (int i = 1; i < n; i++)
    {
        if (p[i - 1] < p[i])
        {
            cnt[i] = cnt[i - 1] + 1;
        }
        else
        {
            cnt[i] = 1;
        }
    }
    //printv(cnt);
    vector<int> ok;
    for (int i = k - 1; i < n; i++)
    {
        if (cnt[i] >= k)
        {
            ok.push_back(i - k + 1);
        }
    }
    // printv(ok);
    int sz = ok.size();
    for (int i = 1; i < sz; i++)
    {
        int pre = ok[i - 1], cur = ok[i];
        //cerr << pre << " " << cur << endl;
        uf.unite(pre, cur);
    }
    for (int i = 0; i + k < n; i++)
    {
        if (mi.query(i, i + k + 1) == p[i] && ma.query(i, i + k + 1) == p[i + k])
        {
            //cerr << i << " " << i + 1 << endl;
            uf.unite(i, i + 1);
        }
    }
    set<int> st;
    for (int i = 0; i <= n-k; i++)
    {
        st.insert(uf.root(i));
    }
    cout << st.size() << endl;
}


Measured memory_bytes: 16128