#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

class SegTree_mx {
public:
    int f;
    vector<int> dat;

    SegTree_mx(ll n) {
        f = 1;
        while (f < n) f *= 2;
        dat.assign(2 * f, /* INIT */ 0);
    }

    void asg(int k, int v) {
        k += f - 1;
        dat[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    int Query(int a, int b) {
        return query(a, b, 0, 0, f);
    }

    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
};

class SegTree_mn {
public:
    int f;
    vector<int> dat;

    SegTree_mn(ll n) {
        f = 1;
        while (f < n) f *= 2;
        dat.assign(2 * f, /* INIT */ 2e9);
    }

    void asg(int k, int v) {
        k += f - 1;
        dat[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    int Query(int a, int b) {
        return query(a, b, 0, 0, f);
    }

    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return 2e9;
        if (a <= l && r <= b) return dat[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};


int main() {
    int n, k;
    cin >> n >> k;
    SegTree_mx mx = SegTree_mx(n);
    SegTree_mn mn = SegTree_mn(n);
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        mx.asg(i, p[i]);
        mn.asg(i, p[i]);
    }

    int idx = 0;
    bool asc[n] = {};
    while (idx < n) {
        int sub = 0;
        while (idx + sub + 1 < n && p[idx + sub] < p[idx + sub + 1]) sub++;
        if (sub + 1 >= k) {
            for (int i = 0; i <= sub - k + 1; i++) {
                asc[idx + i] = 1;
            }
        }
        idx += max(1, sub);
    }
    /*for (int i = 0 ;i < n; i++) cerr << asc[i];
    cerr << endl;*/

    int ans = 1;
    bool uu = 0;
    if (asc[0]) uu = 1;
    for (int i = 0; i < n - k; i++) {
        int q = mx.Query(i, i + k);
        int r = mn.Query(i, i + k);
        //cout << i _ q _ r _ p[i] _ p[i + k] << endl;
        if (p[i] == r && p[i + k] > q) ;
        else {
            if (!uu && asc[i + 1]) {
                uu = 1;  ans++;
            }
            else if (!uu || !asc[i + 1]) {
                ans++;
            }
            //cerr << i << " ";
        }
    }
    cerr << endl;
    cout << ans << endl;
}


Measured memory_bytes: 5376