def DPPPPPPPPPP(l):
    LIS=[1]*len(l)
    for i in range(1,len(l)):
        for j in range(i):
            if l[i]>l[j]:
                LIS[i]=max(LIS[i],LIS[j]+1)
    return LIS
while True:
    try:
        num = int(input())
        stu_list = list(map(int,input().split()))
        count=[]
        left = DPPPPPPPPPP(stu_list)
        right = DPPPPPPPPPP(stu_list[::-1])[::-1]
        for i in range(len(left)):
            count.append(left[i]+right[i]-1)
        print(num-max(count))
    except:
        break