/*

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



struct SegmentTree1 {
private:
    int n;
    vector<int> node;
public:
    SegmentTree1(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, inf);
        //最下段
        for (int i = 0; i < sz; ++i) node[i + (n - 1)] = v[i];
        for (int i = n - 2; i >= 0; --i) //0 ~ n-2, n-1 ~ 2n - 1
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
    void update(int x, int val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
        //再帰であり、最初r = -1. 最初の区間は[0, n)
        if (r < 0) r = n;
        //関係ない区間ならminになり得ないのを
        if (r <= a || b <= l) return inf;
        if (a <= l && r <= b) return node[k];
        
        int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

struct SegmentTree2 {
private:
    int n;
    vector<int> node;
public:
    SegmentTree2(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, -inf);
        //最下段
        for (int i = 0; i < sz; ++i) node[i + (n - 1)] = v[i];
        for (int i = n - 2; i >= 0; --i) //0 ~ n-2, n-1 ~ 2n - 1
            node[i] = max(node[2 * i + 1], node[2 * i + 2]);
        
    }
    void update(int x, int val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
        //再帰であり、最初r = -1. 最初の区間は[0, n)
        if (r < 0) r = n;
        //関係ない区間ならmaxになり得ないのを
        if (r <= a || b <= l) return -inf;
        if (a <= l && r <= b) return node[k];
        
        int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};


random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand100(2, 10);
#define rm rand100(mt)

int main_ac(int n, int k, vector<int> p);

int main() {
    while (1) {
        // cout << 1 << endl;
        int n = rm;
        int k = rm;
        if (k > n) continue;
        
        vector<int> a(n);
        rep(i, n) a[i] = i;
        
        int mod = rm;
        if (gcd(n, mod) != 1) continue;
        
        vector<int> p(n);
        rep(i, n) p[i] = a[i * mod % n];
        rep(i, n) cout << p[i] << " "; cout << endl;
        SegmentTree1 sg1(p);
        SegmentTree2 sg2(p);
        
        int mmin = sg1.getmin(0, k);
        int mmax = sg2.getmax(0, k);
        // cout << mmin << " " << mmax << endl;
        
        int cnt = 0;
        rep(l, n) {
            int r = l + 1;
            while (r < n && p[r - 1] < p[r]) r++;
            r--;
            if (r - l >= k - 1) cnt++;
            // cout << l << " " << r << endl;
            l = r;
        }
        // cout << cnt << endl;
        
        int ans = 1;
        rep3(i, k, n) {
            int tmpmin = sg1.getmin(i - k + 1, i + 1);
            int tmpmax = sg2.getmax(i - k + 1, i + 1);
            // 最大値が入って来てない または 最小値が出て行ってない
            if (tmpmax == mmax || tmpmin == mmin) {
                ans++;
            }
            mmin = tmpmin;
            mmax = tmpmax;
            // cout << mmin << " " << mmax << endl;
        }
        
        int A = main_ac(n, k, p);
        // cout << A << " " << ans - max(0, cnt - 1) << endl;
        if (A != ans - max(0, cnt - 1)) {
            cout << n << " " << k << endl;
            rep(i, n) cout << p[i] << " "; cout << endl;
            cout << A << " " << ans - max(0, cnt - 1) << endl;
            
            
            break;
        }
        
    }
}

int main_ac(int n, int k, vector<int> p) {
   
    int cnt = 0;
    rep(l, n) {
        int r = l + 1;
        while (r < n && p[r - 1] < p[r]) r++;
        if (r - l >= k) cnt++;
        if (r != l) l = r - 1;
        // cout << l << endl;
    }
    if (cnt) cnt--;
    // cout << cnt << endl;
    
    vector<int> mmin(n);
    vector<int> deq(n);
    auto slide_min = [&]() {
        int s = 0, t = 0;
        rep(i, n) {
            while (s < t && p[deq[t - 1]] >= p[i]) t--;
            deq[t++] = i;
            if (i - k + 1 >= 0) {
                mmin[i - k + 1] = p[deq[s]];
                if (deq[s] == i - k + 1) {
                    s++;
                }
            }
        }
    };
    
    vector<int> mmax(n);
    deq.clear();
    deq.resize(n);
    auto slide_max = [&]() {
        int s = 0, t = 0;
        rep(i, n) {
            while (s < t && p[deq[t - 1]] <= p[i]) t--;
            deq[t++] = i;
            if (i - k + 1 >= 0) {
                mmax[i - k + 1] = p[deq[s]];
                if (deq[s] == i - k + 1) {
                    s++;
                }
            }
        }
    };
    
    slide_min();
    // rep(i, n - k + 1) cout << mmin[i] << " "; cout << endl;
    
    slide_max();
    // rep(i, n - k + 1) cout << mmax[i] << " "; cout << endl;
    
    rep3(i, 1, n - k + 1) { // i - 1, i
        if (p[i - 1] == mmin[i - 1] && p[i - 1 + k] == mmax[i]) {
            cnt++;
        }
    }
    
    cnt = (n - k + 1) - cnt;
    return cnt;
}
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



struct SegmentTree1 {
private:
    int n;
    vector<int> node;
public:
    SegmentTree1(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, inf);
        //最下段
        for (int i = 0; i < sz; ++i) node[i + (n - 1)] = v[i];
        for (int i = n - 2; i >= 0; --i) //0 ~ n-2, n-1 ~ 2n - 1
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
    void update(int x, int val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
        //再帰であり、最初r = -1. 最初の区間は[0, n)
        if (r < 0) r = n;
        //関係ない区間ならminになり得ないのを
        if (r <= a || b <= l) return inf;
        if (a <= l && r <= b) return node[k];
        
        int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

struct SegmentTree2 {
private:
    int n;
    vector<int> node;
public:
    SegmentTree2(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, -inf);
        //最下段
        for (int i = 0; i < sz; ++i) node[i + (n - 1)] = v[i];
        for (int i = n - 2; i >= 0; --i) //0 ~ n-2, n-1 ~ 2n - 1
            node[i] = max(node[2 * i + 1], node[2 * i + 2]);
        
    }
    void update(int x, int val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
        //再帰であり、最初r = -1. 最初の区間は[0, n)
        if (r < 0) r = n;
        //関係ない区間ならmaxになり得ないのを
        if (r <= a || b <= l) return -inf;
        if (a <= l && r <= b) return node[k];
        
        int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};




int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int &pi : p) cin >> pi;
    
    SegmentTree1 sg1(p);
    SegmentTree2 sg2(p);
    
    
    int cnt = 0;
    rep(l, n) {
        int r = l + 1;
        while (r < n && p[r - 1] < p[r]) r++;
        if (r - l >= k) cnt++;
        // cout << l << " " << r << endl;
        if (l != r) l = r - 1;
    }
    cnt--;
    chmax(cnt, 0);
    // cout << cnt << endl;
    
    int ans = 1;
    rep(i, n - k) {
        int mmin = sg1.getmin(i, i + k);
        int mmax = sg2.getmax(i + 1, i + k + 1);
        // cout << mmin << " " << mmax << endl;
        if (mmin == p[i] && mmax == p[i + k]) {}
        else ans++;
    }
    // cout << ans << endl;
    cout << ans - cnt << endl;
    
}



Measured memory_bytes: 5872