#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const int MOD=924844033;
template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	using G=function<Monoid(Monoid, OperatorMonoid, int)>;
	using H=function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
	int sz;
	vector<Monoid> data;
	vector<OperatorMonoid> lazy;
	const F f;
	const G g;
	const H h;
	const Monoid e1;
	const OperatorMonoid e0;

	LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
		sz=1;
		while(sz<n) sz<<=1;
		data.resize(2*sz-1, e1);
		lazy.resize(2*sz-1, e0);
	}

	void build(vector<Monoid> v){
		for(int i=0; i<v.size(); i++) data[i+sz-1]=v[i];
		for(int i=sz-2; i>=0; i--) data[i]=f(data[2*i+1], data[2*i+2]);
	}

	void eval(int k, int l, int r){
		if(lazy[k]!=e0){
			data[k]=g(data[k], lazy[k], r-l);
			if(k<sz-1){
				lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
			}
		}
		lazy[k]=e0;
	}

	void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
		eval(k, l, r);
		if(r<=a || b<=l) return;
		if(a<=l && r<=b){
			lazy[k]=h(lazy[k], x);
			eval(k, l, r);
		}else{
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			data[k]=f(data[2*k+1], data[2*k+2]);
		}
	}
	void update(int a, int b, const OperatorMonoid &x){
		return update(a, b, x, 0, 0, sz);
	}

	Monoid find(int a, int b, int k, int l, int r){
		eval(k, l, r);
		if(b<=l || r<=a) return e1;
		if(a<=l && r<=b) return data[k];
		else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
	}
	Monoid find(int a, int b){
		return find(a, b, 0, 0, sz);
	}
	Monoid operator[](const int &k){
		return find(k, k+1);
	}
};
template<typename T>
struct BIT{ //1-indexed
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
int n, k;
ll p[200020];
ll s1[200020], s2[200020];
ll bp1[200020], bp2[200020];
ll b1, b2;
int main()
{
	cin>>n>>k;
	b1=12345678, b2=87654321;
	ll bv1=inv(b1), bv2=inv(b2);
	bp1[0]=bp2[0]=1;
	for(int i=1; i<=n; i++) bp1[i]=bp1[i-1]*b1%MOD, bp2[i]=bp2[i-1]*b2%MOD;
	BIT<int> bit(n);
	auto f=[&](ll a, ll b){ return (a+b)%MOD;};
	auto g=[&](ll a, P p, int len){ return (p.first*a+p.second*len)%MOD;};
	auto h=[&](P p, P q){ return P(p.first*q.first%MOD, (p.second*q.first+q.second)%MOD);};
	LazySegmentTree<ll, P> seg1(n, f, g, h, 0, P(1, 0));
	LazySegmentTree<ll, P> seg2(n, f, g, h, 0, P(1, 0));
	for(int i=0; i<n; i++){
		cin>>p[i];
		s1[i+1]=(s1[i]+bp1[i]*p[i])%MOD;
		s2[i+1]=(s2[i]+bp2[i]*p[i])%MOD;
	}
	for(int i=0; i<k; i++){
		int t=bit.sum(p[i]);
		seg1.update(p[i], p[i]+1, P(0, p[i]*bp1[t]%MOD));
		seg1.update(p[i]+1, n, P(b1, 0));
		seg2.update(p[i], p[i]+1, P(1, p[i]*bp2[t]%MOD));
		seg2.update(p[i]+1, n, P(b2, 0));
		bit.add(p[i]+1, 1);
	}
	set<P> st;
	ll s01=(s1[n]-s1[k]+seg1.find(0, n)+MOD)%MOD, s02=(s2[n]-s2[k]+seg2.find(0, n)+MOD)%MOD;
	st.insert({s01, s02});
	for(int i=k; i<n; i++){
		int t=bit.sum(p[i]);
		seg1.update(p[i], p[i]+1, P(0, p[i]*bp1[t]%MOD));
		seg1.update(p[i]+1, n, P(b1, 0));
		seg2.update(p[i], p[i]+1, P(0, p[i]*bp2[t]%MOD));
		seg2.update(p[i]+1, n, P(b2, 0));
		bit.add(p[i]+1, 1);
		t=bit.sum(p[i-k]);
		seg1.update(p[i-k], p[i-k]+1, P(0, 0));
		seg1.update(p[i-k]+1, n, P(bv1, 0));
		seg2.update(p[i-k], p[i-k]+1, P(0, 0));
		seg2.update(p[i-k]+1, n, P(bv2, 0));
		bit.add(p[i-k]+1, -1);
		s01=(s1[i-k+1]+s1[n]-s1[i+1]+bp1[i-k+1]*seg1.find(0, n)+MOD)%MOD;
		s02=(s2[i-k+1]+s2[n]-s2[i+1]+bp2[i-k+1]*seg2.find(0, n)+MOD)%MOD;
		st.insert({s01, s02});
	}
	cout<<st.size()<<endl;
	return 0;
}

Measured memory_bytes: 45956