#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
const int MXN = 2e6 + 139;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v(n), nxt(n, (long long int)1e18), pos(n + 1, -1);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
    if (pos[v[i]] != -1) nxt[pos[v[i]]] = i;
    pos[v[i]] = i;
  }
  set<pair<long long int, long long int> > st;
  set<long long int> isok;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (isok.find(v[i]) == isok.end()) {
      if ((long long int)st.size() >= k) {
        auto [x, y] = *st.begin();
        st.erase(st.begin());
        isok.erase(y);
      }
      st.insert({-nxt[i], v[i]});
      isok.insert(v[i]);
      ans++;
    } else {
      st.erase({-i, v[i]});
      st.insert({-nxt[i], v[i]});
    }
  }
  cout << ans;
  return 0;
}
