#include <bits/stdc++.h>
using namespace std;
int getnextidx(int i, queue<int> idx[]);
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> req;
  queue<int> idx[n + 1];
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    idx[temp].push(i);
    req.push_back(temp);
  }
  unordered_map<int, int> nextofavail;
  set<pair<int, int> > valkey;
  int cost = 0;
  int curr;
  for (auto it = req.begin(); it != req.end(); it++) {
    curr = (*it);
    idx[curr].pop();
    if (nextofavail.find(curr) == nextofavail.end()) {
      if (nextofavail.size() >= k) {
        int rem_book_num = (*(--valkey.end())).second;
        valkey.erase(make_pair(nextofavail[rem_book_num], rem_book_num));
        nextofavail.erase(rem_book_num);
      }
      nextofavail[curr] = getnextidx(curr, idx);
      valkey.insert(make_pair(nextofavail[curr], curr));
      cost++;
    } else {
      valkey.erase(make_pair(nextofavail[curr], curr));
      nextofavail[curr] = getnextidx(curr, idx);
      valkey.insert(make_pair(nextofavail[curr], curr));
    }
  }
  cout << cost << "\n";
}
int getnextidx(int i, queue<int> idx[]) {
  return (idx[i].empty() ? 500000 : idx[i].front());
}
