#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 400005;
int n, k, a[maxn], lst[maxn], nx[maxn], ins[maxn];
set<int> s;
set<int>::iterator it;
int main() {
  n = rd(), k = rd();
  for (int i = int(1); i <= (int)(n); i++) a[i] = rd();
  for (int i = int(1); i <= (int)(n); i++) nx[lst[a[i]]] = i, lst[a[i]] = i;
  for (int i = int(1); i <= (int)(n); i++)
    if (lst[i]) nx[lst[i]] = n + 1;
  int ans = 0;
  for (int i = int(1); i <= (int)(n); i++) {
    if (ins[a[i]])
      s.erase(i);
    else {
      ans++;
      if (s.size() == k) it = --s.end(), ins[a[*it]] = 0, s.erase(it);
    }
    s.insert(nx[i]), ins[a[i]] = 1;
  }
  rt(ans), putchar('\n');
}
