import sys

def get_max_incre(this_tall):
    N = len(this_tall)
    dp=[1 for i in range(N)]
    for i in range(N):
        maxl = 1
        for j in range(i):
            if this_tall[i]>this_tall[j]:
                this_l = dp[j]+1
                if this_l>maxl:
                    maxl = this_l
        
        dp[i] = maxl
    return dp

if __name__ == "__main__": 
    N = int(input())
    for line in sys.stdin:
        tall = list(map(int,line.split()))
        tall_re = reversed(tall)
        tall_re = list(tall_re)

        l1 = get_max_incre(tall)
        l2 = get_max_incre(tall_re)
        l2.reverse()

        maxl = 0
        for i in range(N):
            if l1[i]+l2[i]>maxl:
                maxl=l1[i]+l2[i]

        print(N-(maxl-1))