#include <bits/stdc++.h>
using namespace std;
long long int div_floor(const long long int &a, const long long int &b) {
  return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
  return a / b + (((a ^ b) >= 0) and a % b);
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &e : a) cin >> e;
  vector<vector<int> > times(n + 1, vector<int>(1, 1e9));
  for (int i = 0; i < n; i++) times[a[i]].push_back(i);
  for (auto &e : times) sort(e.begin(), e.end());
  for (auto &e : times) reverse(e.begin(), e.end());
  set<pair<int, int> > books;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans++;
    if (books.count({i, a[i]}))
      ans--, books.erase({i, a[i]});
    else if ((long long int)books.size() == k)
      books.erase(*books.rbegin());
    times[a[i]].pop_back();
    books.insert({times[a[i]].back(), a[i]});
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
}
