#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 5e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
int dp[MAXN];
int cal[MAXN];
int ccal[MAXN];
int Lid[MAXN];
bool col[MAXN];
bool chk[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
        cal[A[i]]++;
    }

    for(int i=n;i>=1;i--){
        Lid[A[i]] = i;
        if(col[A[i]])continue;
        chk[i] = true;
        col[A[i]] = true;
    }


    for(int i=1;i<=n;i++){
        if(chk[i]){
            cur = A[i];
            dp[i] = dp[Lid[cur]-1]+cal[cur];
            dp[i] = max(dp[i],dp[i-1]);
        }
        else dp[i] = dp[i-1];
    }

    int res = n-dp[n];

    for(int i=n;i>=1;i--){
        ccal[A[i]]++;
        mx = max(mx,ccal[A[i]]);
        res = min(res,n-(dp[i-1]+mx));
    }

    cout<<res<<"\n";

    return 0;
}

