#include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 5;
const int inf = (int)1e9 + 7;
int n, k, ans;
int a[N], has[N], now[N];
vector<int> pos[N];
set<pair<int, int> > s;
int get_nxt(int x, int ps) {
  auto it = upper_bound(pos[x].begin(), pos[x].end(), ps);
  if (it == end(pos[x])) {
    return n + 1;
  } else {
    return *it;
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    pos[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (has[a[i]]) {
      s.erase(make_pair(now[a[i]], a[i]));
      now[a[i]] = get_nxt(a[i], i);
      s.insert(make_pair(now[a[i]], a[i]));
    } else {
      if ((int)s.size() == k) {
        has[(*s.rbegin()).second] = 0;
        s.erase(--s.end());
      }
      ++ans;
      now[a[i]] = get_nxt(a[i], i);
      has[a[i]] = 1;
      s.insert(make_pair(now[a[i]], a[i]));
    }
  }
  printf("%d", ans);
  return 0;
}
