#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
struct Node {
  int e, p;
  bool operator<(const Node& rhs) const {
    return p < rhs.p || (p == rhs.p && e < rhs.e);
  }
};
const int MAXN = 400000 + 400;
int n, k;
int a[MAXN], nextId[MAXN];
bool vis[MAXN];
Node gTop(const set<Node>& s) {
  set<Node>::reverse_iterator it = s.rbegin();
  return *it;
}
void gpop(set<Node>& s) {
  set<Node>::reverse_iterator it = s.rbegin();
  Node temp = *it;
  s.erase(temp);
}
int main() {
  while (scanf("%d%d", &n, &k) == 2) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    map<int, int> M;
    for (int i = n - 1; i >= 0; i--) {
      if (M.count(a[i]))
        nextId[i] = M[a[i]];
      else
        nextId[i] = n;
      M[a[i]] = i;
    }
    set<Node> Q;
    memset(vis, 0, sizeof(vis));
    int qSize = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int ai = a[i];
      if (!vis[ai]) {
        ans++;
        Q.insert(Node{ai, nextId[i]});
        vis[ai] = true;
        qSize++;
        if (qSize > k) {
          if (gTop(Q).e != ai) {
            vis[gTop(Q).e] = false;
            gpop(Q);
            qSize--;
          } else {
            Node temp = gTop(Q);
            gpop(Q);
            vis[gTop(Q).e] = false;
            gpop(Q);
            qSize--;
            Q.insert(temp);
          }
        }
      } else {
        Q.erase(Node{ai, i});
        Q.insert(Node{ai, nextId[i]});
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
