#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define MT make_tuple
#define MP make_pair
#define lastOne(x) (31 - __builtin_clz(x))
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const double PI = 2*acos(0); 
const double EPS =  1e-9;
const int oo = 2e9;
const ll OO = 1e18;
const ll MOD = 1e9+7;

const int N = 5e5+5;
int a[N], l[N], r[N], f[N], dp[N];

int main() 
{
    int n;
    sc(n);
    for (int i = 0; i < n; i++)
    {
        sc(a[i]);
        r[a[i]] = i;
        if (l[a[i]] == 0 && a[0] != a[i])
            l[a[i]] = i;
    }
    dp[n-1] = 1;
    f[a[n-1]]++;
    for (int i = n - 2; i >= 0; i--)
    {
        f[a[i]]++;
        if (l[a[i]] == i)
            dp[i] = f[a[i]] + dp[r[a[i]]+1];
        dp[i] = max(dp[i], f[a[i]]);
        dp[i] = max(dp[i], dp[i+1]);
    }
    
    printf("%d\n", n-dp[0]);
    return 0;
}