#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)	
#define forr(i,x,n)	for(int i = n;i >= x;--i)

const int N = 5e5+7;
int f[N],cnt[N];
int L[N],R[N],a[N];

int main() 
{
	int n;scanf("%d",&n);
	forn(i,1,n)	scanf("%d",&a[i]);
	
	forn(i,1,n)
	{
		if(!L[a[i]])	L[a[i]] = i;
		R[a[i]] = i;
	}
	
	forr(i,1,n)
	{
		++cnt[a[i]];
		if(i == L[a[i]])	f[i] = max(f[i],cnt[a[i]] + f[R[a[i]] + 1]);
		else 	f[i] = max(f[i],cnt[a[i]]);
		
		f[i] = max(f[i],f[i + 1]);
	}
	
	printf("%d",n - f[1]);
	return 0;
}