#include <bits/stdc++.h>
using namespace std;
inline int setBit(int N, int pos) { return N = N | (1 << pos); }
inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }
int A[400000 + 10];
vector<int> nxt[400000 + 10];
int idx[400000 + 10];
struct data {
  int id, p;
};
bool operator<(data a, data b) { return a.p < b.p; }
priority_queue<data> Q;
int holding[400000 + 10];
void validate(int i) {
  while (Q.size() && Q.top().p <= i) Q.pop();
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]), nxt[A[i]].push_back(i);
  for (int i = 1; i <= n; i++) nxt[i].push_back(n + 1), idx[i] = 1;
  int ans = 0;
  int have = 0;
  for (int i = 1; i <= n; i++) {
    if (holding[A[i]] == true) {
      Q.push({A[i], nxt[A[i]][idx[A[i]]]});
      idx[A[i]]++;
    } else {
      if (have < k) {
        have++;
        ans++;
        Q.push({A[i], nxt[A[i]][idx[A[i]]]});
        idx[A[i]]++;
        holding[A[i]] = true;
      } else {
        validate(i);
        ans++;
        holding[Q.top().id] = false;
        Q.pop();
        Q.push({A[i], nxt[A[i]][idx[A[i]]]});
        holding[A[i]] = true;
        idx[A[i]]++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
