#include<iostream>
#include<cstdio>
using namespace std;
int f[100005],r[100005];
int a[100005];
bool ok[100005];
int maxm;
int main(){
	int n;
	scanf("%d",&n);
	for (int i = 0;i < n;++i){
		f[i]=1;
		scanf("%d",&a[i]);
	}
	for (int i = 0;i < n;++i){
		ok[a[i]]=1;
		if (ok[a[i]-1]) {
			f[a[i]]=f[a[i]-1]+1;
		}
		maxm = max(maxm,f[a[i]]);
	}
	printf("%d\n",n-maxm);
	return 0;
}