#include <bits/stdc++.h>
using namespace std;
int n, k, a[666666], nx[666666], np[666666];
struct scmp {
  bool operator()(int a, int b) const {
    if (nx[a] != nx[b]) return nx[a] > nx[b];
    return a < b;
  }
};
set<int, scmp> si;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) nx[i] = n + 1;
  for (int i = n; i >= 1; --i) {
    np[i] = nx[a[i]];
    nx[a[i]] = i;
  }
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    if (si.count(a[i])) {
      si.erase(a[i]);
      nx[a[i]] = np[i];
      si.insert(a[i]);
      continue;
    }
    nx[a[i]] = np[i];
    if (si.size() == k) si.erase(*si.begin());
    si.insert(a[i]);
    ++tmp;
  }
  printf("%d\n", tmp);
}
