#include<bits/stdc++.h>
using namespace std;

int64_t n, dp[500005], a[500005], ri[500005], cnt[500005], lf[500005];

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i]; ri[a[i]] = i;
        if(lf[a[i]] == 0) lf[a[i]] = i;
    }
    for(int i = n; i >= 1; i--){
        cnt[a[i]]++;
        dp[i] = dp[i + 1];
        if(i == lf[a[i]]) dp[i] = max(dp[i], cnt[a[i]] + dp[ri[a[i]] + 1]);
        else dp[i] = max(dp[i], cnt[a[i]]);
    }
    cout << n - dp[1];
}
