#include <bits/stdc++.h>
using namespace std;
int n, k, a[400005], m, ans;
bool b[400005];
queue<int> q[400005];
priority_queue<pair<int, int> > heap;
void solve(int ind) {
  while (!heap.empty()) {
    pair<int, int> T = heap.top();
    heap.pop();
    if (q[T.second].front() != T.first) continue;
    if (!b[T.second]) continue;
    b[T.second] = 0;
    ans++;
    b[a[ind]] = 1;
    return;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    q[a[i]].push(i);
  }
  for (int i = 1; i <= n; i++) q[i].push(n + n);
  for (int i = 0; i < n; i++) {
    if (!b[a[i]]) {
      if (m < k) {
        m++;
        ans++;
        b[a[i]] = 1;
      } else {
        solve(i);
      }
    }
    q[a[i]].pop();
    heap.push((pair<int, int>){q[a[i]].front(), a[i]});
  }
  printf("%d\n", ans);
  return 0;
}
