#include<cstdio>
int min(int a,int b) {return a>b?b:a;}
int a[200304],f[203040];
int main()
{
	int n,now=1,ans=0x7f7f7f7f;
	scanf("%d",&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;
	for (int i=1;i<=n;++i) ans=min(ans,n-f[i]);
	printf("%d",ans);
	return 0;
}