#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 4e5 + 5;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  vector<int> nxt(N, N), mp(N, N);
  for (int i = n - 1; i >= 0; i--) {
    nxt[i] = mp[a[i]];
    mp[a[i]] = i;
  }
  set<pair<int, int>> st;
  map<int, bool> marked;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (marked[a[i]]) {
      st.erase({-i, a[i]});
      st.insert({-nxt[i], a[i]});
      continue;
    }
    if (st.size() == k) {
      pair<int, int> pi = *st.begin();
      st.erase(st.begin());
      marked[pi.second] = false;
    }
    st.insert({-nxt[i], a[i]});
    marked[a[i]] = true;
    ++ans;
  }
  cout << ans;
  return 0;
}
