#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) a[i]--;
  vector<long long> cnt(n, 0);
  vector<vector<long long> > ele(n);
  for (long long i = 0; i < n; i++) ele[a[i]].push_back(i);
  vector<long long> next(n, n);
  long long s = 0, ans = 0;
  set<long long> S;
  for (long long i = 0; i < n; i++) {
    if (cnt[a[i]] == 1) {
      long long in = upper_bound(ele[a[i]].begin(), ele[a[i]].end(), i) -
                     ele[a[i]].begin();
      if (in != ele[a[i]].size()) {
        next[a[i]] = ele[a[i]][in];
      } else
        next[a[i]] = n;
      S.erase(i);
      if (next[a[i]] != n)
        S.insert(next[a[i]]);
      else {
        cnt[a[i]] = 0;
        s--;
      }
    } else {
      if (s < k) {
        cnt[a[i]] = 1;
        long long in = upper_bound(ele[a[i]].begin(), ele[a[i]].end(), i) -
                       ele[a[i]].begin();
        if (in != ele[a[i]].size()) {
          next[a[i]] = ele[a[i]][in];
        } else
          next[a[i]] = n;
        ans++;
        s++;
        if (next[a[i]] != n)
          S.insert(next[a[i]]);
        else {
          s--;
          cnt[a[i]] = 0;
        }
      } else {
        if (S.size() != 0) {
          long long ini = *S.rbegin();
          S.erase(ini);
          ini = a[ini];
          cnt[ini] = 0;
          s--;
        }
        cnt[a[i]] = 1;
        ans++;
        s++;
        long long in = upper_bound(ele[a[i]].begin(), ele[a[i]].end(), i) -
                       ele[a[i]].begin();
        if (in != ele[a[i]].size()) {
          next[a[i]] = ele[a[i]][in];
        } else
          next[a[i]] = n;
        if (next[a[i]] != n)
          S.insert(next[a[i]]);
        else {
          cnt[a[i]] = 0;
          s--;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
