#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator<(mint a, mint b) { return a.n < b.n; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};
mint operator "" _m(unsigned long long n) { return n; }

constexpr int NUM = 3;

mint pw[200001][NUM];
mint base[NUM];

struct hashstr {
  int len = 0;
  array<mint, NUM> val = {};

  hashstr() {}

  explicit hashstr(int x) {
    len = 1;
    rep(i, NUM) {
      val[i] = x;
    }
  }

  friend hashstr operator+(hashstr a, hashstr b) {
    hashstr c = {};
    c.len = a.len + b.len;
    rep(i, NUM) {
      c.val[i] = a.val[i] * pw[b.len][i] + b.val[i];
    }
    return c;
  }

  friend bool operator<(hashstr a, hashstr b) {
    if (a.len != b.len) return a.len < b.len;
    return a.val < b.val;
  }
};

void init_hashstr() {
  mt19937 mt(123);
  rep(i, NUM) {
    base[i] = uniform_int_distribution<int>(1, MOD - 1)(mt);
    pw[0][i] = 1;
  }
  rep(i, 200000) {
    rep(j, NUM) {
      pw[i + 1][j] = pw[i][j] * base[j];
    }
  }
}

template<class T>
class segment_tree {
  int N;
  vector<T> dat;
  T mempty;
  function<T(T, T)> mappend;

public:
  segment_tree(int n, T mempty_, function<T(T, T)> mappend_) : mempty(mempty_), mappend(mappend_) {
    N = 1;
    while (N < n) N *= 2;
    dat.resize(N * 2, mempty);
  }

  void update(int k, T v) {
    k += N;
    dat[k] = v;
    while (k > 1) {
      k >>= 1;
      dat[k] = mappend(dat[k * 2], dat[k * 2 + 1]);
    }
  }

  T query(int l, int r) {
    l += N;
    r += N - 1;
    T x = mempty, y = mempty;
    while (l <= r) {
      if ((l & 1) == 1) x = mappend(x, dat[l++]);
      if ((r & 1) == 0) y = mappend(dat[r--], y);
      l >>= 1;
      r >>= 1;
    }
    return mappend(x, y);
  }

  T query_all() {
    return dat[1];
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  init_hashstr();
  int N, K; cin >> N >> K;
  vector<int> P(N);
  rep(i, N) {
    cin >> P[i];
  }
  segment_tree<hashstr> seg(N, hashstr(), [](hashstr a, hashstr b) { return a + b; });
  vector<hashstr> pref(N + 1);
  vector<hashstr> suff(N + 1);
  for (int i = 0; i < N; i++) {
    pref[i + 1] = pref[i] + hashstr(P[i]);
  }
  for (int i = N - 1; i >= 0; i--) {
    suff[i] = hashstr(P[i]) + suff[i + 1];
  }
  for (int i = 0; i < K - 1; i++) {
    seg.update(P[i], hashstr(P[i]));
  }
  set<hashstr> st;
  for (int i = 0; i + K <= N; i++) {
    seg.update(P[i + K - 1], hashstr(P[i + K - 1]));
    st.insert(pref[i] + seg.query_all() + suff[i + K]);
    seg.update(P[i], hashstr());
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 30336