#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define o 200005
using namespace std;
int n,ans;
int a[o],f[o];
int main(){
	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=max(ans,f[i]);
	cout<<n-ans<<endl;
}