#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int arr[400009], go[400009], last[400009];
set<pair<int, int> > t;
set<int> s;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", arr + i), last[arr[i]] = 1000000007;
  for (int i = n; i >= 1; i--) {
    go[i] = last[arr[i]];
    last[arr[i]] = i;
  }
  int ans = 0;
  memset(last, 0, sizeof last);
  for (int i = 1; i <= n; i++) {
    if (s.count(arr[i])) {
      if (last[arr[i]]) t.erase(make_pair(last[arr[i]], arr[i]));
      t.insert(make_pair(go[i], arr[i]));
      last[arr[i]] = go[i];
      continue;
    }
    if ((int)s.size() == k) {
      pair<int, int> res = *t.rbegin();
      s.erase(res.second);
      t.erase(res);
    }
    s.insert(arr[i]);
    t.insert(make_pair(go[i], arr[i]));
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
