#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)4e5 + 10;
const int MOD = (int)1e9 + 7;
int a[maxn];
set<int> s;
int ls[maxn], nxt[maxn], mark[maxn], lst[maxn];
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 >= 1; i--) {
    if (ls[a[i]] == 0) {
      nxt[i] = n + i;
    } else {
      nxt[i] = ls[a[i]];
      lst[nxt[i]] = i;
    }
    ls[a[i]] = i;
  }
  int ans = 0, num = 0;
  for (int i = 1; i <= n; i++) {
    if (mark[a[i]] == 1) {
      s.erase(lst[i]);
      s.insert(nxt[i]);
    } else if (num < k) {
      num++;
      ans++;
      s.insert(nxt[i]);
    } else {
      int del = (*s.rbegin());
      mark[a[del]] = 0;
      ans++;
      s.erase(del);
      s.insert(nxt[i]);
    }
    mark[a[i]] = 1;
  }
  printf("%d\n", ans);
  return 0;
}
