#include <cstdio>
#include <random>
#include <set>
#include <algorithm>

using namespace std;

mt19937 randomGen(231315);

typedef long long ll;

const int MAXN = 2 * 1e5 + 5;
const int BASE[3] = {11, 13, 17};
const int MOD[3] = {(int)1e9 + 3, (int)1e9 + 7, (int)1e9 + 9};

ll add(ll f, ll s, ll m)
{
    f += s;
    if(f >= m)
    {
        f %= m;
    }
    return f;
}

ll mul(ll f, ll s, ll m)
{
    long long temp = 1LL * f * s;
    if(temp >= m)
    {
        temp %= m;
    }
    return temp;
}

ll pw[3][MAXN];

struct Hash
{
    ll h[3];
    Hash(){};
    Hash(ll _key)
    {
        for(int i = 0; i < 3; i++)
        {
            h[i] = _key;
        }
    }

    void append(Hash h2, ll len)
    {
        for(int i = 0; i < 3; i++)
        {
            h[i] = add(mul(h[i], pw[i][len], MOD[i]), h2.h[i], MOD[i]);
        }
    }

    bool operator<(Hash other) const
    {
        return h[0] < other.h[0] || (h[0] == other.h[0] && h[1] < other.h[1]) || (h[0] == other.h[0] && h[1] == other.h[1] && h[2] < other.h[2]);
    }
};

struct Treap
{
    Treap *left, *right;
    ll priority;
    ll cnt;
    ll key;
    Hash val;

    Treap(ll _key)
    {
        priority = randomGen();
        key = _key;
        val = Hash(key);
        cnt = 1;
        left = right = nullptr;
    }

    void recalc()
    {
        cnt = 1;
        if(left != nullptr)
        {
            cnt += left->cnt;
            val = left->val;
        }
        if(cnt == 1)
            val = Hash(key);
        else
            val.append(Hash(key), 1);
        if(right!= nullptr)
        {
            cnt += right->cnt;
            val.append(right->val, right->cnt);
        }
    }
};

Treap* merge(Treap* sm, Treap* bg)
{
    if(sm == nullptr)
    {
        return bg;
    }
    if(bg == nullptr)
    {
        return sm;
    }
    if(sm->priority > bg->priority)
    {
        sm->right = merge(sm->right, bg);
        sm->recalc();
        return sm;
    }
    else
    {
        bg->left = merge(sm, bg->left);
        bg->recalc();
        return bg;
    }
}

pair <Treap*, Treap*> split(Treap* t, ll key)
{
    if(t == nullptr)
    {
        return {nullptr, nullptr};
    }
    if(t->key < key)
    {
        auto splitResults = split(t->right, key);
        t->right = splitResults.first;
        t->recalc();
        return {t, splitResults.second};
    }
    else
    {
        auto splitResults = split(t->left, key);
        t->left = splitResults.second;
        t->recalc();
        return {splitResults.first, t};
    }
}

Treap* root = nullptr;

void add(ll key)
{
    if(root == nullptr)
    {
        //printf("DAS");
        root = new Treap(key);
        return;
    }
    Treap* t = new Treap(key);
    auto splitResults = split(root, key);
    splitResults.first = merge(splitResults.first, t);
    root = merge(splitResults.first, splitResults.second);
}

void del(ll key)
{
    auto splitResults = split(root, key);
    auto splitResults2 = split(splitResults.second, key + 1);
    root = merge(splitResults.first, splitResults2.second);
}

ll n, k;
ll a[MAXN];

void read_input()
{
    scanf("%lld %lld", &n, &k);

    for(int i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
        a[i]++;
        //a[i] = i + 1;
    }

    for(int j = 0; j < 3; j++)
    {
        pw[j][0] = 1;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            pw[j][i] = mul(pw[j][i - 1], BASE[j], MOD[j]);
        }
    }
}

set <Hash> s;
Hash up[MAXN], dw[MAXN];

void solve()
{
    up[0] = Hash(a[0]);
    for(int i = 1; i < n; i++)
    {
        up[i] = up[i - 1];
        up[i].append(a[i], 1);
    }
    dw[n - 1] = Hash(a[n - 1]);
    for(int i = n - 2; i >= 0; i--)
    {
        dw[i] = a[i];
        dw[i].append(dw[i + 1], n - i - 1);
    }
    for(int i = 0; i < k; i++)
    {
        //printf("DAS");
        add(a[i]);
    }

    //printf("%d\n", root == nullptr);
    Hash tmp = root->val;

    tmp.append(dw[k], n - k);

    s.insert(tmp);

    ll l = 0, r = k - 1;

    for(ll i = 1; i < n; i++)
    {
        //printf("%d\n", i);
        l++; r++;
        if(r == n) break;

        del(a[l - 1]);
        add(a[r]);

        tmp = up[l - 1];
        tmp.append(root->val, k);
        if(r != n - 1)
            tmp.append(dw[r + 1], n - r - 1);

        s.insert(tmp);
    }

    printf("%lld\n", s.size());
}

int main()
{
    read_input();
    solve();

    return 0;
}


Measured memory_bytes: 44032