#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll rd(){
	int f = 1;
	ll x = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();		
	}
	while(ch >= '0' && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

struct SegmentTree{
	int n;
	vector<int> sum,tag;
	SegmentTree(int n):n(n),sum(n << 2),tag(n << 2,-1){}
	void push_up(int i){
		sum[i] = sum[i << 1] + sum[i << 1|1];
	}
	void update(int i,int l,int r,int v){
		sum[i] = (r - l) * v;
		tag[i] = v;
	}
	void push(int i,int l,int r){
		int mid = l + r >> 1;
		if(tag[i] != -1) {
			update(i << 1,l,mid,tag[i]);
			update(i << 1|1,mid,r,tag[i]);
			tag[i] = -1;
		}
	}
	void update(int i,int l,int r,int x,int y,int v){
		if(l >= y || r <= x) return;
		if(l >= x && r <= y) return update(i,l,r,v);
		int mid = l + r >> 1;
		push(i,l,r);
		update(i << 1,l,mid,x,y,v);
		update(i << 1|1,mid,r,x,y,v);
		push_up(i);
	}
	void update(int x,int y,int v){
		update(1,0,n,x,y,v);
	}
	int rangeSum(int i,int l,int r,int x,int y){
		if(l >= y || r <= x) return 0;
		if(l >= x && r <= y) return sum[i];
		int mid = l + r >> 1;
		push(i,l,r);
		return rangeSum(i << 1,l,mid,x,y) + rangeSum(i << 1|1,mid,r,x,y); 
	} 
	int rangeSum(int i,int l,int r){
		return rangeSum(1,0,n,l,r); 
	} 
};


int main(){
	int n = rd();
	vector<int> v(n + 1),l(n + 1),r(n + 1),cnt(n + 1),cnt_pos(n + 1),dp(n + 2);
	for(int i = 1;i <= n;i++){
		v[i] = rd();
		if(!l[v[i]]) l[v[i]] = i;
		r[v[i]] = i;
		cnt[v[i]]++; 
	}
	dp[n + 1] = 0;
	for(int i = n;i >= 1;i--){
		dp[i] = dp[i + 1];
		cnt_pos[v[i]]++;
		if(i == l[v[i]]) 
			dp[i] = max(dp[i],dp[r[v[i]] + 1] + cnt[v[i]]);
		else dp[i] = max(dp[i],cnt_pos[v[i]]);
	}
	cout << n - dp[1];
}


					 	 	    	 	    			  			  	