#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long
#define inl inline
#define re register
#define MAXN 200100
using namespace std;
int n;
int p[MAXN];
int t[MAXN];
int f[MAXN];
int 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;
}

