#include<iostream>
#define MAXN 200100
using namespace std;
int n,p[MAXN],t[MAXN],f[MAXN],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]),t[p[i]]=i;
	for(int i=1;i<=n;i++)
		if(t[p[i]-1]<t[p[i]])f[p[i]]=f[p[i]-1]+1;
		else f[p[i]]=1;
	for(int i=1;i<=n;i++)ans=max(ans,f[i]);
	cout<<n-ans;
	return 0;
}

