#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
const int64_t N = 1e6 + 5;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int64_t n, k;
  cin >> n >> k;
  int64_t arr[n];
  vector<int64_t> next(n + 1, 10000000);
  vector<int64_t> lol(n + 1, -1);
  for (int64_t i = 0; i < n; i++) {
    cin >> arr[i];
    if (lol[arr[i]] == -1) {
    } else {
      next[lol[arr[i]]] = i;
    }
    lol[arr[i]] = i;
  }
  set<pair<int64_t, int64_t>> s;
  map<int64_t, int64_t> book;
  int64_t ans = 0;
  for (int64_t i = 0; i < n; i++) {
    if (book[arr[i]]) {
      s.erase({-i, arr[i]});
      if (next[i] < 10000000) {
        s.insert({-next[i], arr[i]});
      } else {
        book[arr[i]] = 0;
      }
      continue;
    } else {
      if (s.size() == k) {
        book[(*s.begin()).second] = 0;
        s.erase(s.begin());
        ans++;
        s.insert({-next[i], arr[i]});
        book[arr[i]] = 1;
      } else {
        ans++;
        s.insert({-next[i], arr[i]});
        book[arr[i]] = 1;
      }
    }
  }
  cout << ans;
  return 0;
}
