#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 2e9 + 10;
const long double EPS = 1e-9;
const int M = 1e2 + 12;
const int N = 4e5 + 10;
vector<int> v[N];
int a[N], cur[N];
int nxt(int col) {
  if (cur[col] >= v[col].size())
    return INF;
  else
    return v[col][cur[col]];
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    v[a[i]].push_back(i);
  }
  set<pair<int, int> > s;
  int ans = 0;
  for (long long i = 0; i < n; ++i) {
    if (s.count(make_pair(-nxt(a[i]), a[i]))) {
      s.erase(make_pair(-nxt(a[i]), a[i]));
      cur[a[i]]++;
      s.insert(make_pair(-nxt(a[i]), a[i]));
      continue;
    }
    if (s.size() == k) {
      s.erase(s.begin());
    }
    ans++;
    cur[a[i]]++;
    s.insert(make_pair(-nxt(a[i]), a[i]));
  }
  cout << ans;
}
