#include <bits/stdc++.h>
using namespace std;
int main() {
  queue<int>* nextDayBookReq = new queue<int>[400000];
  int nDays;
  int maxCapacity;
  cin >> nDays >> maxCapacity;
  int* bookReq = new int[400000];
  for (int i = 0; i < nDays; ++i) {
    cin >> bookReq[i];
    --bookReq[i];
    nextDayBookReq[bookReq[i]].push(i);
  }
  bool* isBookAvaiable = new bool[400000];
  memset(isBookAvaiable, false, sizeof(bool) * 400000);
  int currentCapacity = 0;
  int minCost = 0;
  set<int> s;
  for (int i = 0; i < nDays; ++i) {
    if (!isBookAvaiable[bookReq[i]]) {
      ++minCost;
      if (currentCapacity == maxCapacity) {
        if (s.size()) {
          int book = *(--s.end());
          s.erase(book);
          isBookAvaiable[bookReq[book]] = 0;
        }
        --currentCapacity;
      }
      isBookAvaiable[bookReq[i]] = 1;
      ++currentCapacity;
      if (nextDayBookReq[bookReq[i]].size()) nextDayBookReq[bookReq[i]].pop();
      if (nextDayBookReq[bookReq[i]].size()) {
        s.insert(nextDayBookReq[bookReq[i]].front());
      } else {
        isBookAvaiable[bookReq[i]] = 0;
        --currentCapacity;
      }
    } else {
      s.erase(s.begin());
      nextDayBookReq[bookReq[i]].pop();
      if (nextDayBookReq[bookReq[i]].size()) {
        s.insert(nextDayBookReq[bookReq[i]].front());
      } else {
        isBookAvaiable[bookReq[i]] = 0;
        --currentCapacity;
      }
    }
  }
  cout << minCost;
  return 0;
}
