#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7;
struct node {
  int x, dis;
  bool operator<(const node &b) const {
    return dis == b.dis ? x < b.x : dis > b.dis;
  }
};
int n, k, a[N], ed, now[N], sz;
multiset<node> st;
vector<int> nxt[N];
int cnt[N];
int main() {
  int ans = 0;
  scanf("%d%d", &n, &k);
  for (int i = (1); i <= (n); ++i) scanf("%d", a + i);
  ed = 1;
  for (int i = (2); i <= (n); ++i)
    if (a[i] != a[ed]) a[++ed] = a[i];
  for (int i = (1); i <= (n); ++i) nxt[a[i]].push_back(i);
  for (int i = (1); i <= (n); ++i) nxt[i].push_back(N);
  for (int i = (1); i <= (ed); ++i) {
    if (now[a[i]] == 0) {
      now[a[i]] = 1;
      sz++;
      ans++;
      if (sz > k) {
        now[(*st.begin()).x] = 0;
        st.erase(st.begin());
        sz--;
      }
    } else {
      multiset<node>::iterator it;
      it = st.lower_bound({a[i], i});
      st.erase(it);
    }
    st.insert({a[i], nxt[a[i]][++cnt[a[i]]]});
  }
  printf("%d\n", ans);
  return 0;
}
