#include <bits/stdc++.h>
#define ll long long
#define N 100003
using namespace std;
ll n,ma;
ll a[N],dp[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    freopen("CAU4.inp","r",stdin);
    freopen("CAU4.out","w",stdout);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++){
        ll j = lower_bound(dp+1,dp+ma+1,a[i])-dp-1;
        dp[j+1] = a[i];
        ma = max(ma,j+1);
    }
    cout << n-ma;
    return 0;
}
