#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
#include<stdint.h>
using namespace std;
#define ll unsigned long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
#include<fstream>
const ll INF=9223372036854775807;
const ll mod=998244353;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
int main()
{
    int n,k;
    cin>>n>>k;
    vll a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    multiset<int>g;
    bool c=false;int spec=0;
    vi cnt(2,0);
    ll ans=0;
    for(int i=0;i<k;i++)
    {
        if(g.size()==0){
            g.insert(a[i]);}
        else
        {
            if(a[i]>*g.rbegin())
            {
                
            }
            else
            {
                
            }
            g.insert(a[i]);
        }
        if(i!=0)
        {
            if(a[i]>a[i-1])
            {
                cnt[0]++;
            }
            else
            {
                cnt[1]++;
            }
        }
    }
    if(cnt[1]==0)
    {
        spec++;
    }
    else
    {
        ans=1;
    }
    for(int i=k;i<n;i++)
    {
        if(a[i]>*g.rbegin()&&a[i-k]==*g.begin())
        {
            g.erase(g.find(a[i-k]));
            g.insert(a[i]);
        }
        else
        {
            if(a[i]>a[i-1])
            {
                cnt[0]++;
            }
            else
            {
                cnt[1]++;
            }
            if(a[i-k]<a[i-k+1])
            {
                cnt[0]--;
            }
            else
            {
                cnt[1]--;
            }
            if(cnt[1]!=0)
            {
                ans++;
            }
            else
            {
                spec=min(spec+1,1);
            }
            g.erase(g.find(a[i-k]));
            g.insert(a[i]);
        }
    }
    cout<<ans+spec;
    
}


Measured memory_bytes: 11136