#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 10;
map<int, int> mp;
int lst[MAXN], nxt[MAXN], a[MAXN], pre[MAXN];
set<int> s;
set<pair<int, int> > my;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  mp.clear();
  my.clear();
  s.clear();
  int n, k, t = 0;
  cin >> n >> k;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    lst[i] = 1e9;
    pre[i] = -1;
    cin >> a[i];
    if (!mp.count(a[i])) mp[a[i]] = t++;
    a[i] = mp[a[i]];
  }
  for (int i = n - 1; i >= 0; i--) {
    nxt[i] = lst[a[i]];
    lst[a[i]] = i;
  }
  int ans = 0;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    if (s.find(a[i]) != s.end()) {
      if (pre[a[i]] >= 0)
        my.erase({nxt[pre[a[i]]], a[i]}), my.insert({nxt[i], a[i]});
      pre[a[i]] = i;
      continue;
    }
    ans++;
    if (((int)(s).size()) == k) {
      int to = (*(--my.end())).second;
      my.erase(--my.end());
      s.erase(to);
    }
    my.insert({nxt[i], a[i]});
    s.insert(a[i]);
    pre[a[i]] = i;
  }
  cout << ans << "\n";
}
