#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 3;

int n, a[maxn], l[maxn], r[maxn], dp[maxn], cnt[maxn], maxi[maxn];
int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		r[a[i]] = i;
	}
	
	for (int i = n - 1; i >= 0; i--)
		l[a[i]] = i;
	
	for (int i = n - 1; i >= 0; i--)
	{
		cnt[a[i]]++;
		dp[i] = cnt[a[i]];
		
		if (r[a[i]] == n - 1)
		{
			if (i == n - 1)
				maxi[i] = dp[i];
			else
				maxi[i] = max(dp[i], maxi[i + 1]);
			continue;
		}
		
		if (i == l[a[i]])
			dp[i] += maxi[r[a[i]] + 1];
			
		maxi[i] = max(dp[i], maxi[i + 1]);
	}
	int res = -1;
	for (int i = 0; i <= n; i++)
		res = max(res, dp[i]);
	cout << n - res;
}
