#include <bits/stdc++.h>
using namespace std;
#define me(a, b) memset(a, b, sizeof(a))
#define IOS() ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
const ll mod = 1e9 + 7;

int a[maxn], cnt[maxn], ma[maxn], dp[maxn], mi[maxn];

int main()
{
    IOS();
    int n;
    cin >> n;
    me(mi, -1);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        ma[a[i]] = i;
        if(mi[a[i]] == -1)
            mi[a[i]] = i;
    }
    for(int i = n-1; i >= 0; --i) {
        dp[i] = dp[i+1];
        ++cnt[a[i]];
        if(i == mi[a[i]])
            dp[i] = max(dp[i], dp[ma[a[i]] + 1] + cnt[a[i]]);
        else dp[i] = max(dp[i], cnt[a[i]]);
    }
    cout << n - dp[0] << endl;
    return 0;
}