#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long arr[n], next[n + 1], last[n + 1];
  for (int i = 0; i < n; i++) cin >> arr[i];
  ;
  memset(last, 4000005, sizeof(last));
  for (int i = n - 1; i >= 0; i--) {
    next[i] = last[arr[i]];
    last[arr[i]] = i;
  }
  int cost = 0;
  multiset<pair<long long, long long> > books_idx;
  map<long long, bool> book_present;
  for (int i = 0; i < n; i++) {
    if (book_present[arr[i]]) {
      auto it = books_idx.find({i, arr[i]});
      if (it != books_idx.end()) {
        books_idx.erase(it);
        books_idx.insert({next[i], arr[i]});
      }
    } else {
      if (books_idx.size() >= k) {
        auto top = *books_idx.rbegin();
        books_idx.erase(--books_idx.end());
        book_present[top.second] = false;
      }
      books_idx.insert({next[i], arr[i]});
      book_present[arr[i]] = true;
      cost++;
    }
  }
  cout << cost << endl;
  return 0;
}
