//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 500005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair <int, int>
#define fi first
#define se second
using namespace std;
typedef long long ll;

int N, a[MAX], fst[MAX], lst[MAX], cnt[MAX];
int dp[MAX];
 
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    optimiza_io
    cin >> N;
    for(int i = 1; i <= N; i ++) {
        fst[i] = N+1;
        lst[i] = -1;
    }

    for(int i = 1; i <= N; i ++) {
        cin >> a[i];
        fst[a[i]] = min(fst[a[i]], i);
        lst[a[i]] = max(lst[a[i]], i);
    }

    for(int i = N; i >= 1; i --) {
        cnt[a[i]]++;
        dp[i] = dp[i + 1];
        if(fst[a[i]] == i)
            dp[i] = max(dp[i], dp[lst[a[i]] + 1] + cnt[a[i]]);
        else 
            dp[i] = max(dp[i], cnt[a[i]]);
    }

    cout << N - dp[1] << "\n";
    return 0;
}
 
// CHECAR LIMITES 