#include <bits/stdc++.h>
using namespace std;
const int N = 400400;
int n, k;
int a[N], have[N], nxt[N], prv[N];
int pos[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (0); i <= (int(n) - 1); ++i) scanf("%d", &a[i]);
  for (int i = (1); i <= (n); ++i) nxt[i] = n + 1;
  for (int i = n - 1; i >= 0; i--) {
    prv[i] = nxt[a[i]];
    nxt[a[i]] = i;
  }
  set<pair<int, int> > q;
  int num = 0, res = 0;
  for (int i = (0); i <= (int(n) - 1); ++i) {
    if (have[a[i]]) {
      q.erase(q.find(make_pair(pos[a[i]], a[i])));
      q.insert(make_pair(prv[i], a[i]));
      pos[a[i]] = prv[i];
      continue;
    }
    if (num < k) {
      have[a[i]] = 1;
      pos[a[i]] = prv[i];
      q.insert(make_pair(prv[i], a[i]));
      res++;
      num++;
    } else {
      pair<int, int> who = *q.rbegin();
      q.erase(q.find(who));
      have[who.second] = 0;
      q.insert(make_pair(prv[i], a[i]));
      res++;
      have[a[i]] = 1;
      pos[a[i]] = prv[i];
    }
  }
  printf("%d\n", res);
  return 0;
}
