#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
inline void umin(T &a, T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void umax(T &a, T b) {
  a = a > b ? a : b;
}
const int N = (int)4e5 + 5;
const int INF = (int)1e9 + 7;
const long long MOD = (long long)1e9 + 7;
int a[N];
vector<int> idx[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = n; i; i--) {
    idx[a[i]].push_back(i);
  }
  set<pair<int, int> > ms;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (ms.count({-idx[a[i]].back(), a[i]})) {
      ms.erase(ms.find({-idx[a[i]].back(), a[i]}));
      idx[a[i]].pop_back();
      if (idx[a[i]].empty())
        ms.insert({-N, a[i]});
      else
        ms.insert({-idx[a[i]].back(), a[i]});
      continue;
    }
    res++;
    if ((int)ms.size() < k) {
      idx[a[i]].pop_back();
      if (idx[a[i]].empty())
        ms.insert({-N, a[i]});
      else
        ms.insert({-idx[a[i]].back(), a[i]});
    } else {
      ms.erase(ms.begin());
      idx[a[i]].pop_back();
      if (idx[a[i]].empty())
        ms.insert({-N, a[i]});
      else
        ms.insert({-idx[a[i]].back(), a[i]});
    }
  }
  printf("%d\n", res);
  return 0;
}
