#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define ll long long
using namespace std;
int n,f[200001],a[200001];
int getnum()
{
    int ans=0;
    bool f=1;
    char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')f=0;
        c=getchar();
    }
    while(isdigit(c))
    {
        ans=ans*10+c-'0';
        c=getchar();
    }
    return f? ans : -ans;
}
int max(int a,int b)
{
    return a>b ? a : b;
}
int main()
{
    n=getnum();
    for(int i=1;i<=n;i++)
    {
        a[i]=getnum();
        f[i]=1;
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(a[j]+1==a[i])
            {
                f[i]=max(f[i],f[j]+1);
            }
        }
        cnt=max(cnt,f[i]);
    }
    cout<<n-cnt;
    return 0;
}