#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define N 200008
using namespace std;
int n,a[N],l1,l2,ans[N],as;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i){
		ans[a[i]]=ans[a[i]-1]+1;
		as=max(as,ans[a[i]]);
	}
	cout<<n-as;
	return 0;
}