#include <bits/stdc++.h>
#define maxn 500010
using namespace std;

int n, a[maxn], f[maxn];
int cnt[maxn], l[maxn], r[maxn], g[maxn];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++ ) l[i] = r[i] = -1;
	for (int i = 1; i <= n; i ++ ) { cin >> a[i]; if (l[a[i]] == -1) l[a[i]] = i; r[a[i]] = i, cnt[a[i]] ++ ; }
	for (int i = n; i; i -- )
	{
		f[i] = f[i + 1], g[a[i]] ++ ;
		if (l[a[i]] == i) f[i] = max(f[i], cnt[a[i]] + f[r[a[i]] + 1]);
		else f[i] = max(f[i], g[a[i]]);
	}
	
	printf("%d\n", n - f[1]);
	return 0;
}