#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    freopen("CAU4.INP","r",stdin);
    freopen("CAU4.OUT","w",stdout);
    cin >> n;
    vector<ll>a(n+2),dp(n+2,1);
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    a[0] = LLONG_MIN;
    a[n+1] = LLONG_MAX;
    for(int i = 0;i <= n+1;i++){
        for(int j = 0;j < i;j++){
            if(a[i] > a[j]){
                dp[i] = max(dp[i],dp[j]+1);
            }
        }
    }
    cout << n-(dp[n+1]-2);
    return 0;
}
