#include <bits/stdc++.h>
using namespace std;
const int CN = 4e5 + 5;
int read() {
  int s = 0, ne = 1;
  char c = getchar();
  while (c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
  return s * ne;
}
int n, k, a[CN], nxt[CN], last[CN], cnt = 0;
bool ins[CN];
class stc {
 public:
  int id, v;
  bool operator<(const stc &a) const { return v < a.v; }
};
stc make(int a, int b) {
  stc c;
  c.id = a, c.v = b;
  return c;
}
priority_queue<stc> Q;
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = n; i; i--) {
    if (!last[a[i]])
      nxt[i] = CN;
    else
      nxt[i] = last[a[i]];
    last[a[i]] = i;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ins[a[i]]) {
      Q.push(make(a[i], nxt[i]));
      continue;
    }
    if (cnt < k)
      cnt++, ans++, ins[a[i]] = true;
    else
      ins[Q.top().id] = false, ins[a[i]] = true, Q.pop(), ans++;
    Q.push(make(a[i], nxt[i]));
  }
  printf("%d", ans);
}
