def func(num,people): lst = [1]*num for i in range(1,num): # i表示后一个人 for j in range(i): # j表示前一个人 if people[j] < people[i]: # 当后一人比前一人高时 lst[i] = max(lst[i],lst[j]+1) # 到后一人为止,当前人数为前人+1或自己中更大的一个 return lst
while 1: try: num = int(input()) people = input().split() people = [int(i) for i in people] left = func(num,people) # 从左往右排每个位置最大数 right = func(num,people[::-1]) # 从右往左排每个位置最大数 stu_list= [left[i]+right[~i]-1 for i in range(num)] # 实际是左顺序与右逆序相加后减一 print(num-max(stu_list)) # 出列数 except: break