import sys

n = int(input().strip())

h = list(map(int, input().strip().split()))

dpl = [1] * n

dpr = [1] * n

for i in range(n):

    for j in range(i):

        if h[i] > h[j]:

            dpl[i] = max(dpl[i], dpl[j]+1)

ret = n

for i in range(n-1, -1, -1):

    for j in range(n-1, i, -1):

        if h[i] > h[j]:

            dpr[i] = max(dpr[i], dpr[j]+1)

    ret = min(ret, n - (dpl[i]+dpr[i]-1))

# for i in range(n):

#     ret = min(ret, n - (dpl[i]+dpr[i]-1))

print(ret)