#include <fstream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	ifstream cin("lock.in");
	ofstream cout("lock.out");
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<int> b;
	for (int i = 0; i < n; i++)
		if (a[i] <= a.back()) b.push_back(a[i]);
	a = b;
	int k = b.size();

	vector<int> nvp(k, 1);
	for (int i = 1; i < k; i++)
	{
		int j = i - 1;
		while (j > nvp[i] - 2)
		{
			if (a[j] <= a[i]) nvp[i] =  max(nvp[i], nvp[j] + 1);
			j--;
		}
	}
	cout << n - nvp.back() << endl;
}


