#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    #define rep(i,l,r) for(int i=(l);i<=(r);i++)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    // const int MOD=993244853;
    // inline int mm(const int x){return x>=MOD?x-MOD:x;}
    // template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    // inline ll qpower(ll x,ll e)
    // {
    //     ll ans=1;GG(e<0);
    //     while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;
    // }
    // ll invm(ll x){return qpower(x,MOD-2);}
    const int N=2e5+10;

    const int base=13331;ll bs[N];const int MOD=993244853;
    const int base2=131;ll bs2[N];const int MOD2=1e9+7;
    namespace Seg
    {
        #define lc 2*x
        #define rc 2*x+1
        #define mid (l+r)/2
        int siz[N*4],hash[N*4],hash2[N*4];
        void add(int x,int l,int r,int pos,int op)
        {
            if(l==r){siz[x]=op;hash[x]=(op?pos:0);hash2[x]=(op?pos:0);return;}
            if(pos<=mid) add(lc,l,mid,pos,op); else add(rc,mid+1,r,pos,op);
            siz[x]=siz[lc]+siz[rc];hash[x]=(hash[lc]*bs[siz[rc]]+hash[rc])%MOD;hash2[x]=(hash2[lc]*bs2[siz[rc]]+hash2[rc])%MOD2;
        }
    };
    set<pr> hh;
    int a[N];
    ll left[N],right[N];
    ll left2[N],right2[N];
    void main()
    {
        bs[0]=1;for(int i=1;i<N;i++) bs[i]=bs[i-1]*base%MOD;
        bs2[0]=1;for(int i=1;i<N;i++) bs2[i]=bs2[i-1]*base2%MOD2;
        int n=qread(),m=qread();for(int i=1;i<=n;i++) a[i]=qread()+1;
        for(int i=1;i<=n;i++) left[i]=(left[i-1]*base+a[i])%MOD;for(int i=n;i>=1;i--) right[i]=(right[i+1]+a[i]*bs[n-i])%MOD;
        for(int i=1;i<=n;i++) left2[i]=(left2[i-1]*base2+a[i])%MOD2;for(int i=n;i>=1;i--) right2[i]=(right2[i+1]+a[i]*bs2[n-i])%MOD2;

        for(int i=1;i<=m;i++) Seg::add(1,1,n,a[i],1);
        hh.insert( MP((bs[n-m]*Seg::hash[1]+right[m+1])%MOD,(bs2[n-m]*Seg::hash2[1]+right2[m+1])%MOD2) );
        for(int i=m+1;i<=n;i++)
        {
            Seg::add(1,1,n,a[i],1);Seg::add(1,1,n,a[i-m],0);
            ll hhh=left[i-m]*bs[n-(i-m)]+Seg::hash[1]*bs[n-i]+right[i+1];
            ll hhh2=left2[i-m]*bs2[n-(i-m)]+Seg::hash2[1]*bs2[n-i]+right2[i+1];
            hh.insert(MP(hhh%MOD,hhh2%MOD2));
        }write(sz(hh));
    }
};//(ans+MOD)%MOD
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 29184