#include <bits/stdc++.h>
using namespace std;
void func(void) {
  freopen("input.c", "r", stdin);
  freopen("output.c", "w", stdout);
}
const int N = 5e5 + 10;
long long has[N], a[N];
set<pair<long long, long long> > s;
vector<long long> cnt[N];
long long now[N];
int main() {
  long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, m, fg = 0,
                     mx = 0, mx1 = 0, mn = 8000000000000000000,
                     mn1 = 8000000000000000000;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[i] = x;
    cnt[x].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    int cur = a[i];
    if (has[cur]) {
      s.erase({cnt[cur][now[cur]], cur});
      if (now[cur] + 1 > cnt[cur].size() - 1) {
        has[cur] = 0;
      } else {
        s.insert({cnt[cur][now[cur] + 1], cur});
        now[cur]++;
      }
    } else {
      if (s.size() == k) {
        auto it = s.end();
        it--;
        pair<long long, long long> p = *it;
        has[p.second] = 0;
        s.erase(it);
        has[cur] = 1;
        if (now[cur] + 1 > cnt[cur].size() - 1) {
          has[cur] = 0;
        } else {
          s.insert({cnt[cur][now[cur] + 1], cur});
          now[cur]++;
        }
      } else {
        has[cur] = 1;
        if (now[cur] + 1 > cnt[cur].size() - 1) {
          has[cur] = 0;
        } else {
          s.insert({cnt[cur][now[cur] + 1], cur});
          now[cur]++;
        }
      }
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
