#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int N[200010];
int dp[200010];

int main ()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		dp[i] = 1, N[i] = 0;
	for(int i = 0; i < n; i++)
		scanf("%d", &N[i]);
	
	int max = 0;
	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j < i; j++)
		{
			if(N[i] == N[j] + 1)
				dp[i] += dp[j];
		}
		if(dp[i] > max)
			max = dp[i];
	}
	
	cout << n - max << endl;
	
	return 0;
}