#include <bits/stdc++.h>   int mod = 1000000007;   using namespace std;   using namespace std;   int n, k;   int a[400005];   int pos[400005];   map<int, int> m;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     cin >> n >> k;     for (int i = 1; i <= n; i++) pos[i] = 1e7;     m[a[1]] = 1e7;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       pos[m[a[i]]] = i;       m[a[i]] = i;     }     int ans = 0;     set<int> s;     set<pair<int, int> > ss;     for (int i = 1; i <= n; i++) {       if (!s.count(a[i])) {         if (s.size() < k) {           ans++;           s.insert(a[i]);           ss.insert(make_pair(pos[i], a[i]));         } else {           ans++;           set<pair<int, int> >::iterator it = ss.end();           it--;           int val = (*it).second;           ss.erase(it);           s.erase((val));           s.insert(a[i]);           ss.insert(make_pair(pos[i], a[i]));         }       } else {         ss.erase(ss.begin());         ss.insert(make_pair(pos[i], a[i]));       }     }     cout << ans;   }   