#include <bits/stdc++.h>
using namespace std;
inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f=-1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 5e5+100;

int T,n,m,q,k;
int a[maxn];
int rr[maxn],num[maxn];
int af[maxn];
struct Node
{
    int l,r,num;
    bool operator<(const Node y)const
    {
        return l<y.l;
    }
}nd[maxn];
int dp[maxn];
int main()
{
    n = read();
    for(int i=1; i<=n; i++) a[i] = read();
    for(int i=1; i<=n; i++) rr[a[i]] = nd[a[i]].r = i, nd[a[i]].num++;
    for(int i=n; i>=1; i--) nd[a[i]].l = i;
    sort(nd+1,nd+1+n);
    //memset(dp,0x3f3f3f3f,sizeof(dp));
    dp[n+1] = 0;
    for(int i=n,j=n; i>=1; i--)
    {
        while(j>=1 && nd[j].l>i) j--;
        af[a[i]]++;
        if(nd[j].l==i)
        {
            dp[i] = max(dp[i],dp[nd[j].r+1]+nd[j].num);
        }
        else dp[i] = max(dp[i],af[a[i]]);
        //else dp[i] = dp[i+1];
        //dp[i] = min(dp[i],dp[i+1]+1);
        dp[i] = max(dp[i],dp[i+1]);
    }
    cout << n-dp[1] << endl;
    //for(int i=1; i<=n; i++) cout << dp[i] << ' ';
    //cout << endl;
    return 0;
}
