#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
//#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
//t in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
ll p = 2000083, m[] = {998244353, 1000000009}, in[2], inv[2][1000010], pot[2][1000010];
ll poto(ll b, ll e, ll mo)
{
	ll res = 1;
	while(e > 0)
	{
		if(e & 1) res = res * b % mo;
		b = b * b % mo;
		e /= 2;
	}
	return res;
}
void inih()
{
	fore(i, 0, 2)
	{
		pot[i][0] = 1;
		fore(j, 0, 1000009)
			pot[i][j+1] = pot[i][j] * p % m[i];
	}
}
struct node{
    int key, pri, siz;
    ll hs[2];
    node *l, *r;
    node() {}
    node(int key) : key(key), pri(rand()), l(NULL), r(NULL), siz(1) 
    {
    	 hs[0] = key;
    	 hs[1] = key;
    }
};
typedef node* pnode;
int sz(pnode t)
{
    return (t?t->siz:0);
}
ll hs(pnode t, int in)
{
	return (t? t-> hs[in] : 0);
}
void up_sz(pnode t)
{
    if(t)
    {
    	int le =  sz(t->l), ri = sz(t->r);
    	t->siz = le + 1 + ri;
    	fore(i, 0, 2)
    	{
    		t->hs[i] = ((hs(t->l, i) + pot[i][le] * t->key % m[i] + hs(t->r, i) * pot[i][le + 1] % m[i]) % m[i]);
    	}
    }
}
void split(pnode t, pnode &l, pnode &r, int val)
{
    if(!t) r = l = NULL;
    else if(t->key <= val) split(t->r, t->r, r, val), l = t;
    else split(t->l, l, t->l, val), r = t;
    up_sz(t);
}
void merge(pnode &t, pnode l, pnode r)
{
    if(!l || !r) t=(l?l:r);
    else if(l->pri >= r->pri) merge(l->r, l->r, r), t = l;
    else merge(r->l, l, r->l),t=r;
    up_sz(t);
}
void print(pnode t)
{
	if(t)
	{
		print(t->l);
		cout<<t->key<<' ';
		print(t->r);
	}
}

struct Hash
{
	int p = 2000083, m[2], in[2];
	vector<int> h[2], inv[2];
	Hash(vector<int> s)
	{
		m[0] = 998244353, m[1] = 1000000009;
		fore(i, 0, 2)
		{
			in[i] = poto(p, m[i]-2, m[i]);
			h[i].resize(s.size() + 1);
			inv[i].resize(s.size() + 1);
			ll acu = 1;
			h[i][0] = 0, inv[i][0] = 1;
			fore(j, 0, s.size())
			{
				h[i][j + 1] = (h[i][j] + acu * s[j]) % m[i];
				inv[i][j + 1] = (1ll * inv[i][j] * in[i]) % m[i];
				acu = (acu * p) % m[i];
			}
		}
	}
	ll get(int b, int e)
	{
		if(b == e) return 0;
		ll ha[2];
		fore(i, 0, 2)
			ha[i] = ((((h[i][e] - h[i][b]) * (ll)inv[i][b]) % m[i]) + m[i]) % m[i];
		return((ha[0] << 32) | ha[1]) ;
	}
};
ll mulpo(int in, ll ha)
{
	ll ha1 = ha >> 32;
	ll ha2 = (ha << 32) >> 32;
	ha1 = ha1 * pot[0][in] % m[0];
	ha2 = ha2 * pot[1][in] % m[1];
	return (ha1 << 32) + ha2;
}
ll suha(ll a, ll b)
{
	ll h1 = a >> 32, h2 = (a<<32) >>32;
	ll j1 = b >> 32, j2 = (b<<32) >>32;
	h1= (h1 + j1) % m[0];
	h2= (h2 + j2) % m[1];
	return (h1 << 32) + h2;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	inih();
	int n, k;
	cin>>n>>k;
	vector<int> ar(n);
	fore(i, 0, n) cin>>ar[i], ar[i]++;
	Hash ha(ar);
	set<ll> st;
	pnode t = NULL, t1 = NULL, t2 = NULL, t3 = NULL;
	fore(i, 0, k) 
	{
		t3 = new node(ar[i]);
		split(t, t1, t2, ar[i]);
		merge(t1, t1, t3);
		merge(t, t1, t2);
	}
	st.insert(suha((hs(t, 0)<<32) + hs(t, 1), mulpo(k, ha.get( k, n))));
		//print(t);
		//cout<<'\n';
		//cout<<(hs(t, 0)<<32) + hs(t, 1)<<' '<<ha.get( k, n)<<'\n';
		//cout<<suha((hs(t, 0)<<32) + hs(t, 1), mulpo(k, ha.get( k, n)))<<'\n';
	fore(i, k, n)
	{
		split(t, t1, t2, ar[i-k]);
		split(t1, t1, t3, ar[i-k] - 1);
		merge(t, t1, t2);
		t3 = new node(ar[i]);
		split(t, t1, t2, ar[i]);
		merge(t1, t1, t3);
		merge(t, t1, t2);
		//print(t);
		//cout<<'\n';
		st.insert(suha(suha(ha.get(0, i - k + 1), mulpo(i - k + 1, (hs(t, 0)<<32) + hs(t, 1))), mulpo(i + 1, ha.get(i + 1, n))));
		//cout<<i+1<<' '<<n<<'\n';
		//cout<<ha.get(0, i - k + 1)<<' '<<(hs(t, 0)<<32) + hs(t, 1)<<' '<<ha.get(i + 1, n)<<'\n';
		//cout<<suha(suha(ha.get(0, i - k + 1), mulpo(i - k + 1, (hs(t, 0)<<32) + hs(t, 1))), mulpo(i + 1, ha.get(i + 1, n)))<<'\n';
	}
	cout<<st.size();
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 42480