#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 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; }

struct hstr {
  static constexpr int LEN = 200000;
  static constexpr int NUM = 3;
  static mint pw[LEN + 1][NUM];
  static mint base[NUM];

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

  static void init() {
    mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
    for (int i = 0; i < NUM; i++) {
      base[i] = uniform_int_distribution<int>(1, MOD - 1)(mt);
      pw[0][i] = 1;
    }
    for (int i = 0; i < LEN; i++) {
      for (int j = 0; j < NUM; j++) {
        pw[i + 1][j] = pw[i][j] * base[j];
      }
    }
  }

  hstr() {}

  explicit hstr(int x) {
    len = 1;
    for (int i = 0; i < NUM; i++) {
      val[i] = x;
    }
  }

  friend hstr operator+(hstr a, hstr b) {
    hstr c = {};
    c.len = a.len + b.len;
    for (int i = 0; i < NUM; i++) {
      c.val[i] = a.val[i] * pw[b.len][i] + b.val[i];
    }
    return c;
  }

  friend bool operator<(hstr a, hstr b) {
    if (a.len != b.len) return a.len < b.len;
    for (int i = 0; i < NUM; i++) {
      if (a.val[i] != b.val[i]) return (int)a.val[i] < (int)b.val[i];
    }
    return false;
  }
};
mint hstr::pw[hstr::LEN + 1][hstr::NUM];
mint hstr::base[hstr::NUM];

template<class T, class F>
class segment_tree {
  int N;
  vector<T> dat;
  T mempty;
  F mappend;

public:
  segment_tree(int n, function<T(int)> init, T mempty_, F mappend_) : mempty(mempty_), mappend(mappend_) {
    N = 1;
    while (N < n) N *= 2;
    dat.resize(N * 2, mempty);
    for (int i = 0; i < n; i++) {
      dat[i + N] = init(i);
    }
    for (int i = N - 1; i >= 1; i--) {
      dat[i] = mappend(dat[i * 2], dat[i * 2 + 1]);
    }
  }

  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];
  }
};
template<class T, class F>
segment_tree<T, F> create_segment_tree(int n, function<T(int)> init, T mempty, F mappend) {
  return segment_tree<T, F>(n, init, mempty, mappend);
}

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

Measured memory_bytes: 30336