#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
#define BASE 200003
using namespace std;
mt19937 mt(9312);
typedef long long ll;
typedef unsigned long long ull;

int n, k;
int arr[MAXN];
ull base[MAXN];

void init()
{
    base[0] = 1;
    base[1] = BASE;
    for (int i = 2; i < MAXN; ++i)
        base[i] = base[i-1] * BASE;
}

struct node
{
    int key, priority, sz;
    node *left, *right;
    ull hash;
    node (int _key)
    {
        key = _key;
        priority = mt();
        sz = 1;
        left = nullptr;
        right = nullptr;
        hash = _key * 1ULL;
    }
    void recalc()
    {
        int sz_left = (left == nullptr ? 0 : left->sz);
        int sz_right = (right == nullptr ? 0 : right->sz);
        ull hash_left = (left == nullptr ? 0 : left->hash);
        ull hash_right = (right == nullptr ? 0 : right->hash);
        hash = hash_right;
        hash += (ull)(key * base[sz_right]);
        hash += (ull)(hash_left * base[sz_right+1]);
        sz = 1;
        sz += sz_left;
        sz += sz_right;
    }
};

void print(node *t)
{
    if (t == nullptr)
        return;
    print(t->left);
    cout << t->key << " ";
    print(t->right);
}

node *merge(node *sm, node *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 <node*, node*> split(node *t, int val)
{
    if (t == nullptr)
        return {nullptr, nullptr};
    if (t->key < val)
    {
        auto splitResults = split(t->right, val);
        t->right = splitResults.first;
        t->recalc();
        return {t, splitResults.second};
    }
    else
    {
        auto splitResults = split(t->left, val);
        t->left = splitResults.second;
        t->recalc();
        return {splitResults.first, t};
    }
}

node *root;

void add_element(int key)
{
    if (root == nullptr)
    {
        root = new node(key);
        return;
    }
    node *newTreap = new node(key);
    auto splitResults = split(root, key);
    root = merge(splitResults.first, merge(newTreap, splitResults.second));
}

void remove_element(int key)
{
    if (root == nullptr)
        return;
    auto splitResults1 = split(root, key);
    auto splitResults2 = split(splitResults1.second, key + 1);
    root = merge(splitResults1.first, splitResults2.second);
}

vector <ull> hashes;
ull hash_at[MAXN];
ull hash_from[MAXN];

void input()
{
    ull curr = 0;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        ++arr[i];
        curr *= BASE;
        curr += arr[i];
        hash_at[i] = curr;
        ///cout << "i: " << i << "; hash: " << curr << endl;
        ///cout << "i: " << i << "; base: " << base[i] << endl;
    }
    curr = 0;
    hash_from[n] = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        curr += arr[i] * base[n-i-1];
        hash_from[i] = curr;
        ///cout << arr[i] << " " << base[n-i-1] << endl;
        ///cout << "i: "  << i << "; hash: " << curr << endl;
    }
    root = nullptr;
    for (int i = 0; i < k; ++i)
    {
        add_element(arr[i]);
        ///cout << "root hash: " << root->hash << endl;
    }
    curr = root->hash * base[n-k];
    curr += hash_from[k];
    hashes.push_back(curr);
    ///cout << "root: ";
    ///print(root);
    ///cout << endl;
    ///cout << "hash: " << curr << endl;
    for (int i = k; i < n; ++i)
    {
        remove_element(arr[i-k]);
        add_element(arr[i]);
        curr = hash_at[i-k] * base[n-i+k-1];
        ///cout << "i: " << i << "; hash_at " << i - k << ": " << hash_at[i-k] << "; base " << n - i + k - 1 << ": " << base[n-i+k-1] << endl;
        ///cout << "i: " << i << "; root hash: " << root->hash << "; curr:" << curr << endl;
        curr += root->hash * base[n-i-1];
        ///cout << curr << endl;
        curr += hash_from[i+1];
        hashes.push_back(curr);
        ///cout << "root: ";
        ///print(root);
        ///cout << endl;
        ///cout << "hash: " << curr << endl;
    }
    sort(hashes.begin(), hashes.end());
    int cnt = 1;
    for (int i = 1; i < hashes.size(); ++i)
        if (hashes[i] != hashes[i-1])
            ++cnt;
    cout << cnt << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    init();
    input();

    return 0;
}


Measured memory_bytes: 16624