#include <bits/stdc++.h>
using namespace std;
const int MAX = 4e5 + 111;
int n, k;
int a[MAX], nxt[MAX], lst[MAX];
set<pair<int, int> > st, ts;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  fill(lst, lst + MAX, n);
  for (int i = n - 1; i >= 0; --i) {
    nxt[i] = lst[a[i]];
    lst[a[i]] = i;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    set<pair<int, int> >::iterator it = st.lower_bound(make_pair(a[i], -1));
    if (it != st.end() && (*it).first == a[i]) {
      int nx = (*it).second;
      st.erase(*it);
      ts.erase(make_pair(nx, a[i]));
      st.insert(make_pair(a[i], nxt[i]));
      ts.insert(make_pair(nxt[i], a[i]));
    } else if ((int)st.size() < k) {
      st.insert(make_pair(a[i], nxt[i]));
      ts.insert(make_pair(nxt[i], a[i]));
      ++ans;
    } else {
      set<pair<int, int> >::reverse_iterator it = ts.rbegin();
      pair<int, int> p = make_pair((*it).second, (*it).first);
      st.erase(p);
      ts.erase(*it);
      st.insert(make_pair(a[i], nxt[i]));
      ts.insert(make_pair(nxt[i], a[i]));
      ++ans;
    }
  }
  cout << ans;
  return 0;
}
