#include <bits/stdc++.h>
#define N 200200
using namespace std;
typedef long long ll;

int n, p[N], f[N], ans;

int main() {// freopen("_in.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",p+i);
	for (int i=1;i<=n;i++) f[p[i]] = f[p[i]-1] + 1;
	for (int i=1;i<=n;i++) ans = max(ans,f[i]);
	printf("%d\n",n - ans);
}