import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] height = new int[n];
int[] ilen = new int[n];
int[] dlen = new int[n];
for(int i = 0; i < n; i++){
height[i] = input.nextInt();
}
for(int i = 0; i < n; i++){
ilen[i] = 1;
for(int j = 0; j < i; j++){
if(height[j] < height[i] && ilen[i] < (ilen[j] + 1)){
ilen[i]++;
}
}
}
for(int i = (n - 1); i >= 0; i--){
dlen[i] = 1;
for(int j = (n - 1); j > i; j--){
if(height[j] < height[i] && dlen[i] < (dlen[j] + 1)){
dlen[i]++;
}
}
}
int max = 0;
for(int i = 0; i < n; i++){
if(max < (ilen[i] + dlen[i] - 1)){
max = ilen[i] + dlen[i] - 1;
}
}
System.out.println(n - max);
}
}
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] height = new int[n];
int[] ilen = new int[n];
int[] dlen = new int[n];
for(int i = 0; i < n; i++){
height[i] = input.nextInt();
}
for(int i = 0; i < n; i++){
ilen[i] = 1;
for(int j = 0; j < i; j++){
if(height[j] < height[i] && ilen[i] < (ilen[j] + 1)){
ilen[i]++;
}
}
}
for(int i = (n - 1); i >= 0; i--){
dlen[i] = 1;
for(int j = (n - 1); j > i; j--){
if(height[j] < height[i] && dlen[i] < (dlen[j] + 1)){
dlen[i]++;
}
}
}
int max = 0;
for(int i = 0; i < n; i++){
if(max < (ilen[i] + dlen[i] - 1)){
max = ilen[i] + dlen[i] - 1;
}
}
System.out.println(n - max);
}
}