#include <iostream>
#include <algorithm>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cmath>
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i < _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i > _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i < _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)
typedef long long ll;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int dp[200005],maxi = 1;
    int n,a,c = 1;
    cin >> n;
    FOR(i,1,n+1)
    {
    	cin >> a;
//    	cout << a[i] << endl;
    	dp[a] = i;
	}
	FOR(i,1,n+1)
	{
//		cout << dp[i] <<endl;
	    if(dp[i+1] > dp[i])
	    {
	    	c++;
		}
		else
		{
			c = 1;
		}
//		cout << c << endl;
		if(maxi < c)
        {
            maxi = c;
        }
	}
	cout << n - maxi;
    return 0;
}