#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400000 + 5;
const int INF = 1e8;
int a[MAXN];
int nxt[MAXN];
int tmp[MAXN];
bool vis[MAXN];
int solve(const int n, const int m) {
  for (int i(1); i <= n; ++i) tmp[i] = n + 1;
  for (int i(n); i; --i) {
    nxt[i] = tmp[a[i]];
    tmp[a[i]] = i;
  }
  memset(vis, false, sizeof vis);
  set<pair<int, int> > st1;
  set<pair<int, int> > st2;
  int sum(0), res(0);
  for (int i(1); i <= n; ++i) {
    int cur(a[i]);
    if (vis[cur]) {
      auto it1 = st1.lower_bound(pair<int, int>(cur, -1));
      if ((it1->first) != cur) puts("fuck");
      int next_time = it1->second;
      st1.erase(pair<int, int>(cur, next_time));
      st2.erase(pair<int, int>(next_time, cur));
      st1.insert(pair<int, int>(cur, nxt[i]));
      st2.insert(pair<int, int>(nxt[i], cur));
    } else {
      if (sum == m) {
        auto it2 = st2.rbegin();
        int val = it2->second;
        int next_time = it2->first;
        st2.erase(pair<int, int>(next_time, val));
        st1.erase(pair<int, int>(val, next_time));
        vis[val] = false;
        --sum;
      }
      ++sum;
      ++res;
      vis[cur] = true;
      st1.insert(pair<int, int>(cur, nxt[i]));
      st2.insert(pair<int, int>(nxt[i], cur));
    }
  }
  return res;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i(1); i <= n; ++i) scanf("%d", a + i);
  printf("%d\n", solve(n, m));
  return 0;
}
