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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> data(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}
	vector<int> longest(n+1);
	int x = -1;
	for(int i = 0; i < n; i++) {
		longest[data[i]] = longest[data[i] - 1] + 1;
		x = max(x, longest[data[i]]);
	}
	printf("%d\n", n-x);
}