#include <bits/stdc++.h>
#define N 500005
using namespace std;
int a[N],f[N],l[N],c[N],dp[N];
int main(){
    int n;cin >> n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(!f[a[i]])f[a[i]] = i;
        l[a[i]] = i;
    }
    for(int i=n;i;i--)dp[i] = max(dp[i+1],(i==f[a[i]])*dp[l[a[i]]+1]+(++c[a[i]]));
    cout << n-dp[1];
}