/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=5*1e5+100;
int n,a[N],dp[N],b[N],col[N],w,v[N],vi[N];
int l[N],r[N],sum[N],last[N];
vector <pair<int,int> > p[N];
inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),v[a[i]]++,vi[a[i]]=1;
	for (int i=1;i<=n;)
	{
		int j=i;
		while (j<=n&&a[i]==a[j]) j++;
		b[++w]=j-i;col[w]=a[i];
		i=j;
	}
	for (int i=w;i>=1;i--) sum[i]=sum[last[col[i]]]+b[i],last[col[i]]=i;
	for (int i=1;i<=w;i++) r[col[i]]=i;
	for (int i=w;i>=1;i--) l[col[i]]=i;
	for (int i=1;i<=n;i++)
	{
		if (!vi[i]) continue;
		// printf("%d %d %d\n",l[i],r[i],v[i]);
		p[r[i]].push_back(m_k(l[i],v[i]));
	}
	for (int i=1;i<w;i++)
	{
		dp[i]=dp[i-1];
		for (int j=0;j<(int)p[i].size();j++)
		{
			int l=p[i][j].first,val=p[i][j].second;
			// printf("%d %d\n",l,val);
			dp[i]=max(dp[i],dp[l-1]+val);
		}
	}
	dp[w]=dp[w-1];
	for (int i=1;i<=w;i++) dp[w]=max(dp[w],dp[i-1]+sum[i]);
	printf("%d\n",n-dp[w]);
}
