#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline void priv(vector<int> a) {
  for (int i = 0; i < ((int)(a).size()); ++i)
    printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < ((int)(v).size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
const int MX = 400005, INF = 1001001001;
const long long int LINF = 1e18;
const double eps = 1e-10;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  cin >> a;
  set<pair<int, int> > s;
  vector<int> pi(n);
  vector<int> cp(MX, -INF);
  for (int i = (n)-1; i >= 0; --i) {
    pi[i] = cp[a[i]];
    cp[a[i]] = -1 - i;
  }
  vector<int> fl(MX);
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (fl[a[i]]) {
      s.erase(pair<int, int>(fl[a[i]], a[i]));
      fl[a[i]] = pi[i];
      s.insert(pair<int, int>(fl[a[i]], a[i]));
      continue;
    }
    ++ans;
    if ((int)(s).size() == m) {
      pair<int, int> p = *(s.begin());
      s.erase(s.begin());
      fl[p.second] = 0;
    }
    fl[a[i]] = pi[i];
    s.insert(pair<int, int>(pi[i], a[i]));
  }
  cout << ans << endl;
  return 0;
}
