#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e6 + 9;
vector<vector<int>> g;
int a[MAXN];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, k;
  cin >> n >> k;
  g.resize(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    g[a[i]].push_back(i);
  }
  set<pair<int, int>> pq;
  set<int> have;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (have.count(a[i])) {
      auto it = lower_bound(g[a[i]].begin(), g[a[i]].end(), i);
      it--;
      pq.erase({*it, a[i]});
      auto nxt = upper_bound(g[a[i]].begin(), g[a[i]].end(), i);
      if (nxt == g[a[i]].end()) {
        pq.insert({1e9, a[i]});
      } else
        pq.insert({*nxt, a[i]});
      continue;
    }
    ans++;
    if ((int)have.size() == k) {
      auto x = pq.rbegin();
      have.erase(x->second);
      pq.erase(*x);
    }
    have.insert(a[i]);
    auto nxt = upper_bound(g[a[i]].begin(), g[a[i]].end(), i);
    if (nxt == g[a[i]].end()) {
      pq.insert({1e9, a[i]});
    } else
      pq.insert({*nxt, a[i]});
  }
  cout << ans << '\n';
}
