#include <bits/stdc++.h>
using namespace std;
const int maxn = 400010;
priority_queue<pair<int, int> > pq, del;
int pos[maxn], nxt[maxn], a[maxn], vis[maxn];
int main() {
  int n, k, tot = 0, ans = 0;
  scanf("%d%d", &n, &k);
  memset(pos, 0x3f, sizeof(pos));
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = n; i >= 1; i--) nxt[i] = pos[a[i]], pos[a[i]] = i;
  for (int i = 1; i <= n; i++) {
    if (vis[a[i]]) {
      del.push(make_pair(i, a[i]));
      pq.push(make_pair(nxt[i], a[i]));
    } else if (tot < k) {
      pq.push(make_pair(nxt[i], a[i]));
      tot++;
      ans++;
      vis[a[i]] = 1;
    } else {
      while (!del.empty() && pq.top() == del.top()) pq.pop(), del.pop();
      pair<int, int> u = pq.top();
      pq.pop();
      vis[u.second] = 0;
      pq.push(make_pair(nxt[i], a[i]));
      ans++;
      vis[a[i]] = 1;
    }
  }
  printf("%d\n", ans);
}
