#include <iostream>

using namespace std;
const int N = 5e5+10;
int a[N], l[N],r[N],cnt[N],f[N];
int main()
{
    ios::sync_with_stdio(false);
    int n;
        cin>>n;
        for(int i = 1; i <= n; i++){
        cin>>a[i];
        //cnt[a[i]]++;
        }
        for(int i = 1; i <= n; i++){
            if(!l[a[i]]) {
               l[a[i]]=i;
            }
            r[a[i]] = i;
        }
        for(int i = n; i; i--){
            f[i]=f[i+1];
            int x=a[i];
            cnt[x]++;
            if(i==l[x])
            f[i]=max(f[i],cnt[x]+f[r[x]+1]);
            else
            f[i]=max(f[i],cnt[x]);
        }
        cout<<n-f[1]<<endl;
    return 0;
}
    