#include <bits/stdc++.h>
using namespace std;
int n, k, a[400005], nxt[400005], ans;
vector<int> v[400005];
set<int> st;
set<int>::iterator it;
priority_queue<pair<int, int> > q;
void solve() {
  int i = 1;
  while (i <= n && st.size() < k) {
    st.insert(a[i]);
    q.push({nxt[i], a[i]});
    i++;
  }
  ans = st.size();
  for (i; i <= n; i++) {
    if (st.find(a[i]) != st.end()) {
      q.push({nxt[i], a[i]});
      continue;
    }
    if (st.size() < k) {
      st.insert(a[i]);
      ans++;
      q.push({nxt[i], a[i]});
      continue;
    }
    ans++;
    while (q.size() && st.find(q.top().second) == st.end()) q.pop();
    st.erase(st.find(q.top().second));
    q.pop();
    st.insert(a[i]);
    q.push({nxt[i], a[i]});
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      int idx = v[i][j];
      if (j < (int)v[i].size() - 1)
        nxt[idx] = v[i][j + 1];
      else
        nxt[idx] = 1e9;
    }
  }
  solve();
  cout << ans;
  return 0;
}
