#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int max_n = 200222, inf = 111111111;
const int p1 = 222247;
const int p2 = 222269;
const int mod = 1000000007;

int pw1[max_n];
long long pw2[max_n];

int mul(int x, int y) {
    return 1LL * x * y % mod;
}

void get_all_pw() {
    pw1[0] = 1;
    pw2[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        pw1[i] = mul(pw1[i - 1], p1);
        pw2[i] = pw2[i - 1] * p2;
    }
}

struct treap {
    int sz, value, prior;
    int h1;
    long long h2;
    treap *left, *right;
    treap(int v) {
        h1 = h2 = value = v;
        sz = 1;
        prior = rand() * rand();
        left = NULL;
        right = NULL;
    }
};

int get_size(treap *t) {
    if (t == NULL) {
        return 0;
    }
    return t->sz;
}

int get_h1(treap *t) {
    if (t == NULL) {
        return 0;
    }
    return t->h1;
}

long long get_h2(treap *t) {
    if (t == NULL) {
        return 0;
    }
    return t->h2;
}

void update(treap *&t) {
    if (t == NULL) {
        return;
    }
    t->sz = 1 + get_size(t->left) + get_size(t->right);
    t->h1 = (1LL * get_h1(t->left) * pw1[1 + get_size(t->right)] + 1LL * t->value * pw1[get_size(t->right)] + get_h1(t->right)) % mod;
    t->h2 = get_h2(t->left) * pw2[1 + get_size(t->right)] + t->value * pw2[get_size(t->right)] + get_h2(t->right);
}
treap *merge(treap *t1, treap *t2) {
    if (t1 == NULL) {
        return t2;
    }
    if (t2 == NULL) {
        return t1;
    }
    if (t1->prior <= t2->prior) {
        t2->left = merge(t1, t2->left);
        update(t2);
        return t2;
    } else {
        t1->right = merge(t1->right, t2);
        update(t1);
        return t1;
    }
}

void split(treap *our, int key, treap *&l, treap *&r) {
    if (our == NULL) {
        l = NULL;
        r = NULL;
        return;
    }
    if (our->value >= key) {
        r = our;
        split(r->left, key, l, r->left);
    } else {
        l = our;
        split(l->right, key, l->right, r);
    }
    update(l);
    update(r);
}

void add(treap *&t, int x) {
    treap *nt = new treap(x);
    treap *buf1, *buf2;
    split(t, x, buf1, buf2);
    t = merge(buf1, merge(nt, buf2));
}

void erase(treap *&t, int x) {
    treap *buf1, *buf2, *buf3, *buf4;
    split(t, x, buf1, buf2);
    split(buf2, x + 1, buf3, buf4);
    t = merge(buf1, buf4);
}

treap *t;
int n, k, a[max_n];
vector<pair<int, long long>> all;
//vector<vector<int>> q;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    get_all_pw();
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        ++a[i];
    }
    t = NULL;
    for (int i = 0; i < k; ++i) {
        add(t, a[i]);
    }
    int lh1 = 0, rh1 = 0;
    long long lh2 = 0, rh2 = 0;
    for (int i = 0; i < n; ++i) {
        rh1 = (1LL * rh1 * p1 + a[i]) % mod;
        rh2 = rh2 * p2 + a[i];
    }
    for (int i = 0; i < k; ++i) {
        rh1 += mod - mul(a[i], pw1[n - i - 1]);
        rh1 %= mod;
        rh2 -= a[i] * pw2[n - i - 1];
    }
    for (int i = k; i <= n; ++i) {
        //cout << get_h1(t) << " " << get_h2(t) << endl;
        //vector<int> v = {a, a + n};
        //sort(v.begin() + i - k, v.begin() + i);
        //q.push_back(v);

        int h1 = (lh1 + 1LL * get_h1(t) * pw1[n - i] + rh1) % mod;
        long long h2 = lh2 + get_h2(t) * pw2[n - i] + rh2;
        //cout << h1 << " " << h2 << endl;
        all.push_back({h1, h2});

        erase(t, a[i - k]);
        add(t, a[i]);

        lh1 += mul(a[i - k], pw1[n - 1 - i + k]);
        lh1 %= mod;
        lh2 += a[i - k] * pw2[n - 1 - i + k];

        rh1 += mod - mul(a[i], pw1[n - i - 1]);
        rh1 %= mod;
        rh2 -= a[i] * pw2[n - i - 1];
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    printf("%d\n", all.size());

    /*for (auto v : q) {
        for (int x : v) {
            cout << x << " ";
        }
        cout << endl;
    }*/
    return 0;
}


Measured memory_bytes: 16880