#include <bits/stdc++.h>
using namespace std;
const int len = 4e5 + 10;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int nex[len];
int r[len];
int a[len];
priority_queue<pair<int, int> > qu;
set<pair<int, int> > se;
set<int> vis;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n; i >= 1; --i) {
    if (r[a[i]] == 0)
      nex[i] = inf, r[a[i]] = i;
    else {
      nex[i] = r[a[i]];
      r[a[i]] = i;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = vis.count(a[i]);
    if (x) {
      se.erase(se.find({i, a[i]}));
      se.insert({nex[i], a[i]});
    } else {
      if (se.size() == k) {
        pair<int, int> p = *se.rbegin();
        vis.erase(p.second);
        se.erase(*se.rbegin());
      }
      ans++;
      vis.insert(a[i]);
      se.insert({nex[i], a[i]});
    }
  }
  cout << ans << endl;
}
