#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 600000
int a[MAXN];
ll mod=1e9+7;
ll n,m;
int pos[MAXN];
int nxt[MAXN];
int dp[MAXN];
int r[MAXN];
int cnt[MAXN];
int c[MAXN];
int l[MAXN];
int main()
{
    //freopen("./tt.txt","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=n;i>=1;i--)
    {
        nxt[i]=pos[a[i]];
        pos[a[i]]=i;
        cnt[i]=++c[a[i]];
        r[a[i]]=max(i,r[a[i]]);
        l[a[i]]=i;
    }
    dp[n]=1;
    for(int i=n-1;i>=1;i--)
    {
        dp[i]=dp[i+1];
        if(i==l[a[i]])
            dp[i]=max(dp[i],dp[r[a[i]]+1]+cnt[i]);
        else
            dp[i]=max(dp[i],cnt[i]);
    }
    cout<<n-dp[1]<<endl;
}
