#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long sum = 0, f = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
  for (; isdigit(ch); ch = getchar())
    sum = ((sum << 1) + (sum << 3) + (ch ^ 48));
  return f ? -sum : sum;
}
void write(const long long x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
char get() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
long long n, m, cnt, ans, b[4400000], e[4400000], inf = 998244353123456;
struct abc {
  long long a, t;
} a[4400000];
struct nd {
  long long i, nxt;
};
bool operator<(nd a, nd b) { return a.nxt < b.nxt; }
priority_queue<nd> q;
int main() {
  n = read(), m = read();
  for (register long long i = (1); i <= (n); i++) a[i].a = read();
  for (register long long i = (n); i >= (1); i--) {
    if (!b[a[i].a])
      a[i].t = inf;
    else
      a[i].t = b[a[i].a];
    b[a[i].a] = i;
  }
  memset(b, 0, sizeof(b));
  for (register long long i = (1); i <= (n); i++) {
    if (!b[a[i].a]) {
      ans++;
      cnt++;
      if (cnt > m) b[a[q.top().i].a] = 0, q.pop(), cnt--;
      b[a[i].a] = 1;
    }
    q.push((nd){i, a[i].t});
  }
  write(ans);
}
