#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int MA = 998244353, MB = 1000000007;
const int N = 200005;

struct Hash
{
    int a, b;

    Hash(): a(0), b(0)
    {
    }
    Hash(int x): a(x), b(x)
    {
    }
    Hash(int x, int y): a(x), b(y)
    {
    }

    Hash operator + (const Hash &x) const
    {
        return Hash((a + x.a) % MA, (b + x.b) % MB);
    }
    Hash operator + (int x) const
    {
        return Hash((a + x) % MA, (b + x) % MB);
    }
    Hash operator - (const Hash &x) const
    {
        return Hash((a - x.a + MA) % MA, (b - x.b + MB) % MB);
    }
    Hash operator - (int x) const
    {
        return Hash((a - x + MA) % MA, (b - x + MB) % MB);
    }
    Hash operator * (const Hash &x) const
    {
        return Hash((a * (ll)x.a) % MA, (b * (ll)x.b) % MB);
    }
    Hash operator * (int x) const
    {
        return Hash((a * (ll)x) % MA, (b * (ll)x) % MB);
    }
    bool operator == (const Hash &x) const
    {
        return a == x.a && b == x.b;
    }
    bool operator < (const Hash &x) const
    {
        return mp(a, b) < mp(x.a, x.b);
    }
};
const Hash BASE = Hash(N);
Hash RBASE;

int bpow(int x, ll y, int m)
{
    int res = 1;
    for (; y; y >>= 1)
    {
        if (y & 1)
            res = (res * (ll)x) % m;
        x = x * (ll)x % m;
    }
    return res;
}

Hash pw[N];
Hash rpw[N];

int p[N];
Hash pref[N];
Hash suf[N];

Hash t[4 * N];
int sum[4 * N];

void flip(int v, int vl, int vr, int i)
{
    if (vl == vr)
    {
        if (sum[v] == 0)
        {
            sum[v] = 1;
            t[v] = i;
        }
        else
        {
            sum[v] = 0;
            t[v] = 0;
        }
        return;
    }
    int vm = (vl + vr) >> 1;
    if (i <= vm)
        flip(v << 1, vl, vm, i);
    else
        flip(v << 1 | 1, vm + 1, vr, i);
    sum[v] = sum[v << 1] + sum[v << 1 | 1];
    t[v] = t[v << 1] * pw[sum[v << 1 | 1]] + t[v << 1 | 1];
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    pw[0] = rpw[0] = Hash(1);
    RBASE = Hash(bpow(N, MA - 2, MA), bpow(N, MB - 2, MB));
    for (int i = 1; i < N; ++i)
    {
        pw[i] = BASE * pw[i - 1];
        rpw[i] = BASE * rpw[i - 1];
    }
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        cin >> p[i];
        p[i]++;
    }
    for (int i = 1; i <= n; ++i)
    {
        pref[i] = pref[i - 1] * BASE + p[i];
    }
    for (int i = n; i >= 1; --i)
    {
        suf[i] = suf[i + 1] + pw[n - i] * p[i];
    }
    for (int i = 1; i <= k; ++i)
    {
        flip(1, 1, n, p[i]);
    }
    set<Hash> setik;
    for (int l = 1, r = k; r <= n; ++l, ++r)
    {
        setik.insert((pref[l - 1] * pw[sum[1]] + t[1]) * pw[n - r] + suf[r + 1]);
        flip(1, 1, n, p[l]);
        flip(1, 1, n, p[r + 1]);
    }
    cout << setik.size() << '\n';

    return 0;
}

Measured memory_bytes: 25984