func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int BASE = 27;   const int N = 200000 + 2;   const int LOGN = 20;   const long long oo = 1e18;   const double EPS = 1e-9;   int n, q, a[N], mn[N], mx[N], freq[N], dsu[N], bst[N], sum[N];   int find(int i) { return dsu[i] == i ? i : dsu[i] = find(dsu[i]); }   struct seg {     int l, r, val;     seg(int _l, int _r, int _val) { l = _l, r = _r, val = _val; }     bool operator<(const seg& sg) const { return l < sg.l; }   };   vector<seg> cln;   vector<seg> sg;   int main() {     memset(mn, -1, sizeof mn);     cin >> n >> q;     for (int i = 1; i <= 200000; ++i) dsu[i] = i;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       freq[a[i]]++;       if (mn[a[i]] == -1) {         mn[a[i]] = mx[a[i]] = i;       }       mx[a[i]] = max(mx[a[i]], i);       mn[a[i]] = min(mn[a[i]], i);     }     for (int i = 1; i <= 200000; ++i) {       if (mn[i] == -1) continue;       sg.push_back(seg(mn[i], mx[i], i));     }     sort(sg.begin(), sg.end());     for (int i = 0; i < sg.size(); ++i) {       if (cln.size() && cln.back().r >= sg[i].l) {         dsu[find(cln.back().val)] = find(sg[i].val);         cln.back().r = max(cln.back().r, sg[i].r);         continue;       }       cln.push_back(sg[i]);     }     for (int i = 1; i <= 200000; ++i) {       if (mn[i] == -1) continue;       bst[find(i)] = max(bst[find(i)], freq[i]);       sum[find(i)] += freq[i];     }     int ans = 0;     for (int i = 1; i <= 200000; ++i) {       if (find(i) == i) {         ans += sum[i] - bst[i];       }     }     cout << ans << endl;     return 0;   }   