#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll f(vector<ll> &v, ll k){
    set<vector<ll> > se;
    rep(i,0,v.sz-k+1){
      vector<ll> v0 = v;
      vector<ll> v1;
      rep(j,0,k){
        v1.pb(v[i+j]);
      }
      sort(all(v1));
      rep(j,0,k){
          v0[i+j]=v1[j];
      }
      se.insert(v0);
    }
    return se.sz;
}

#define N_MAX (1<<20)
#define INF 1000000000000000000LL

struct segmn{
  long long nn;
  long long dat[(2 * N_MAX) - 1];

  void init(long long n1){
    nn = 1;

    while(nn < n1)nn *= 2;

    for(long long i = 0; i < 2 * nn - 1; i++){
      dat[i] = INF;
    }
  }

  void update(long long k, long long a){
    k += nn - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l)return INF;

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

  long long query(long long a, long long b){
    return query(a,b,0,0,nn);
  }
}segmn1;

struct segmx{
  long long nn;
  long long dat[(2 * N_MAX) - 1];

  void init(long long n1){
    nn = 1;

    while(nn < n1)nn *= 2;

    for(long long i = 0; i < 2 * nn - 1; i++){
      dat[i] = -INF;
    }
  }

  void update(long long k, long long a){
    k += nn - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l)return -INF;

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

  long long query(long long a, long long b){
    return query(a,b,0,0,nn);
  }
}segmx1;

ll f1(vector<ll> &v, ll k){
    segmx1.init(v.sz+10);
    segmn1.init(v.sz+10);
    rep(i,0,v.sz){
      segmx1.update(i,v[i]);
      segmn1.update(i,v[i]);
    }
    ll ans1 = v.sz-k+1;
    ll ans2 = 0;
    ll ans3 = 0;
    vector<ll> v1;
    ll c = 1;
    rep(i,1,v.sz){
        if(v[i-1]<v[i])c++;
        else{
          v1.pb(c);
          c = 1;
        }
    }
    v1.pb(c);
    rep(i,0,v1.sz){
      if(v1[i]>=k){
          ans2++;
      }
    }
    ll k1 = k-1;
    rep(i,1,v.sz-k1){
        ll mx = segmx1.query(i,i+k1);
        ll mn = segmn1.query(i,i+k1);
        if(v[i-1]<mn&&mx<v[i+k1]){
          ans3++;
        }
    }
    return ans1-max(0LL,ans2-1)-ans3;
}

int main() {
  ll n,k;
  cin>>n>>k;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  cout << f1(v,k) << endl;
  return 0;
  ll nn = 9;
  rep(i,2,nn){
   cout <<  "a" << " " << i << endl;
    vector<ll> vv;
    rep(j,1,nn+1){
      vv.pb(j);
    }
    do{
        ll a = f(vv,i);
        ll b = f1(vv,i);
        if(a!=b){
            cout <<  a  << " " << b << endl;
            cout <<   i << endl;
            rep(j,0,nn){
              cout <<   vv[j] << " ";
            }
            cout << endl;
        }
    }while(next_permutation(all(vv)));
  }
  return 0;
}

Measured memory_bytes: 16368