#include<set>
#include<map>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 200005;
const double eps = 1e-8;
#define ll long long
int a[maxn];
int dp[maxn];
int main()
{
	int N;
	scanf("%d",&N);
	int ans = -1; 
	for(int i = 0; i < N; i++)
	{
		scanf("%d",&a[i]);
		dp[i] = 1;
		for(int j = 0; j < i; j++)
		{
			if(a[j] == a[i] - 1)
				dp[i] = max(dp[i], dp[j] + 1);
		}
		ans = max(dp[i], ans);
	}
	ans = N - ans;
	printf("%d\n",ans);
	return 0;
}