#include<iostream>
#include<cstdio>
int a[200001];
int f[200001];
int cnt,l,r,mid,ans,maxn=0;
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		f[a[i]]=f[a[i]-1]+1;
		maxn=max(maxn,f[a[i]]);
	}
	cout<<n-maxn;
}