import sys data = sys.stdin.readlines() n = int(data[0]) l = data[1].split(" ") for i in range(len(l)): l[i] = int(l[i]) left=[1 for i in range(len(l))] right=[1 for k in range(len(l))] for i in range(1,len(l)): for ii in range(0,i): if l[i]>l[ii] and left[ii]+1>left[i]: left[i]=left[ii]+1 j=len(l)-i-1 for jj in range(len(l)-1,j,-1): if l[j]>l[jj] and right[jj]+1>right[j]: right[j]=right[jj]+1 max=left[0]+right[0] for i in range(len(left)): if left[i]+right[i]>max: max=left[i]+right[i] print(len(l)-max+1)