#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
int n;
vector<int>a;
int L[500005];
int R[500005];
int f[500005];
int cf[500005];
int dp[500005];

void input();



void solve(){

    for(int i=0;i<n;i++){
        if(f[a[i]]==0)L[a[i]] = i+1;
        R[a[i]] = i+1;
        f[a[i]]++;
    }
    for(int i=n-1;i>=0;i--){
        dp[i+1] = dp[i+2];
        cf[a[i]]++;

        if(L[a[i]] == i+1){
            dp[i+1] = max(dp[R[a[i]]+1] + f[a[i]], dp[i+1]);
        }
        else{
            dp[i+1] = max(dp[i+1],cf[a[i]]);
        }

    }

    cout<<n - (dp[1])<<"\n";
}

void Clear(){

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    input();
    solve();
    Clear();
}

void input(){
    cin>>n;

    for(int i=0;i<n;i++){
        int x;
        cin>>x;

        a.pb(x);
    }
}
