#include <bits/stdc++.h>
using namespace std;
int v[400005];
queue<int> need[400005];
struct prioritize {
  bool operator()(int a, int b) { return need[a].front() < need[b].front(); }
};
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    need[v[i]].push(i);
  }
  for (int i = 1; i <= n; i++) need[i].push(0x3f3f3f3f);
  set<int, prioritize> s;
  set<int, prioritize>::iterator it;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    it = s.begin();
    if (it != s.end() && (*it) == v[i]) {
      s.erase(it);
      need[v[i]].pop();
      s.insert(v[i]);
      continue;
    }
    if (s.size() >= k) {
      it = s.end();
      it--;
      s.erase(it);
    }
    need[v[i]].pop();
    s.insert(v[i]);
    ans++;
  }
  printf("%d\n", ans);
}
