import heapq N = int(input()) A = list(map(int,input().split())) A = sorted([(i+1,A[i]) for i in range(N-1)],key=lambda x:x[1]) INFTY = 10**6 dp = [INFTY for _ in range(N+1)] dp[N] = 0 heap1 = [] heap2 = [(-N,dp[N])] for j in range(N-2,-1,-1): i,r = A[j] while heap2: if -heap2[0][0]>r: heapq.heappop(heap2) elif i+1<=-heap2[0][0]<=r: k,v = heapq.heappop(heap2) k = -k heapq.heappush(heap1,(v,k)) else:break while heap1 and heap1[0][1]>r: heapq.heappop(heap1) dp[i] = dp[i+1]+1 if heap1: dp[i] = min(heap1[0][0]+1,dp[i]) heapq.heappush(heap2,(-i,dp[i])) print(dp[1])