#include<bits/stdc++.h>
using namespace std;

int n, c[200005];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int A;
		scanf("%d",&A);
		c[A] = c[A-1] + 1;
	}
	int M = 0;
	for(int i=1;i<=n;i++) {
		M = max(M, c[i]);
	}
	printf("%d\n",n-M);
}
