#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int np(const vector<int>& arr) {
int n = arr.size();
if (n == 0) return 0;
vector<int> dp(n, 1);
for (int i = 1; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (arr[i] >= arr[j]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
// Maksymalna wartość w tablicy dp daje długość najdłuższego niemalejącego podciągu
return *max_element(dp.begin(), dp.end());
}
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
int lnds_length = np(arr);
int deletions = n - lnds_length; // Liczba elementów do usunięcia
cout <<n - lnds_length;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgppbnQgbnAoY29uc3QgdmVjdG9yPGludD4mIGFycikgewogICAgaW50IG4gPSBhcnIuc2l6ZSgpOwogICAgaWYgKG4gPT0gMCkgcmV0dXJuIDA7CgogICAgdmVjdG9yPGludD4gZHAobiwgMSk7IAoKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbjsgKytpKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBpOyArK2opIHsKICAgICAgICAgICAgaWYgKGFycltpXSA+PSBhcnJbal0pIHsgCiAgICAgICAgICAgICAgICBkcFtpXSA9IG1heChkcFtpXSwgZHBbal0gKyAxKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICAvLyBNYWtzeW1hbG5hIHdhcnRvxZvEhyB3IHRhYmxpY3kgZHAgZGFqZSBkxYJ1Z2/Fm8SHIG5hamTFgnXFvHN6ZWdvIG5pZW1hbGVqxIVjZWdvIHBvZGNpxIVndQogICAgcmV0dXJuICptYXhfZWxlbWVudChkcC5iZWdpbigpLCBkcC5lbmQoKSk7Cn0KCmludCBtYWluKCkgewogICAgaW50IG47CiAgICBjaW4gPj4gbjsKCiAgICB2ZWN0b3I8aW50PiBhcnIobik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGNpbiA+PiBhcnJbaV07CiAgICB9CgogICAgaW50IGxuZHNfbGVuZ3RoID0gbnAoYXJyKTsKICAgIGludCBkZWxldGlvbnMgPSBuIC0gbG5kc19sZW5ndGg7IC8vIExpY3piYSBlbGVtZW50w7N3IGRvIHVzdW5pxJljaWEKCiAgICBjb3V0IDw8biAtIGxuZHNfbGVuZ3RoOwogICAgcmV0dXJuIDA7Cn0K