#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400005;
int sel[MAXN];
int a[MAXN];
int nxt[MAXN];
int tp[MAXN];
priority_queue<pair<int, int> > pq;
int main() {
  int n, k, siz = 0, ans = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  memset(tp, -1, sizeof tp);
  for (int i = n; i; i--) {
    if (~tp[a[i]]) {
      nxt[i] = tp[a[i]];
    } else {
      nxt[i] = MAXN;
    }
    tp[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (sel[a[i]]) {
      pq.push(make_pair(nxt[i], a[i]));
      continue;
    }
    if (siz == k) {
      while (sel[pq.top().second] == 0) pq.pop();
      pair<int, int> t = pq.top();
      pq.pop();
      assert(sel[t.second] == 1);
      sel[t.second] = 0;
      siz--;
    }
    pq.push(make_pair(nxt[i], a[i]));
    assert(sel[a[i]] == 0);
    sel[a[i]] = 1;
    siz++;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
