/* Question: For a sequence, it starts to rise strictly, and then the longest length of the strict drop is the deformation of the longest ascending subsequence. For I, (from left to right) calculates the longest length of the two ascending subsequences, find the longest length */# include <cstdio> # include <vector> # include <iostream> # include <algorithm> using namespace std; const int MAX = 1000000 + 10; int left_l [MAX], right_r [MAX]; int arr [MAX]; vector <int> vt; int main () {int n; while (scanf ("% d ", & n )! = EOF) {for (int I = 0; I <n; I ++) {scanf ("% d", & arr [I]);} vt. clear (); for (int I = 0; I <n; I ++) {if (vt. empty () | vt. back () <arr [I]) vt. push_back (arr [I]); else {int pt = lower_bound (vt. begin (), vt. end (), arr [I])-vt. begin (); vt [pt] = arr [I];} left_l [I] = vt. size ();} vt. clear (); for (int I = n-1; I> = 0; I --) {if (vt. empty () | vt. back () <arr [I]) vt. push_back (arr [I]); else {int pt = lower_bound (vt. begin (), vt. end (), arr [I])-vt. begin (); vt [pt] = arr [I];} right_r [I] = vt. size () ;}/ * for (I = 0; I <n; I ++) printf ("% d", left_l [I]); printf ("\ n"); for (I = 0; I <n; I ++) printf ("% d", right_r [I]); printf ("\ n"); */int ans = 0; for (int I = 0; I <n; I ++) {if (left_l [I] + right_r [I]> ans) ans = left_l [I] + right_r [I];} printf ("% d \ n ", n-ans + 1);} return 0 ;}