#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 10;
int n, k, ans, len;
int b[MAXN];
bool vis[MAXN];
struct node {
  int num, next;
  bool operator<(const node& x) const { return next < x.next; }
} t[MAXN];
priority_queue<node> q;
int main() {
  ios ::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> t[i].num;
  for (int i = n; i >= 1; i--) {
    int num = t[i].num;
    if (!b[num]) {
      t[i].next = n + 1;
    } else {
      t[i].next = b[num];
    }
    b[num] = i;
  }
  for (int i = 1; i <= n; i++) {
    int num = t[i].num;
    if (!vis[num]) {
      ans++, len++;
      if (len > k) {
        int top = q.top().num;
        q.pop();
        vis[top] = 0;
      }
      vis[num] = 1;
    }
    q.push(t[i]);
  }
  cout << ans << endl;
  return 0;
}
