#include <iostream>
#include <cstring>
using namespace std;

    const int N = 110;
    int a[N], dp1[N], dp2[N];

    int main() {
int n;
while (cin >> n) {
    memset(dp1, 0, sizeof dp1);
    memset(dp2, 0, sizeof dp2);
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++) {
        dp1[i] = 1;
        for (int j = 1; j < i; j++)
            if (a[j] < a[i])
                dp1[i] = max(dp1[i], dp1[j] + 1);
    }

    for (int i = n; i; i--) {
        dp2[i] = 1;
        for (int j = n; j > i; j--)
            if (a[j] < a[i])
                dp2[i] = max(dp2[i], dp2[j] + 1);
    }

    int res = 0;
    for (int i = 1; i <= n; i++)
        res = max(res, dp1[i] + dp2[i] - 1);

    cout << n - res << endl;
}
return 0;
}