N = int(input()) A = list(map(int,input().split())) AA = [] for i in range(N): AA.append((A[i], i)) AAS = sorted(AA) l = [True]*N count = 0 for i in range(1,N+1): v = AAS[i-1][1] if l[v] == False: continue flg = False if v != 0: if l[v-1]: l[v-1] = False count += 1 flg = True else: count += 1 flg = True if flg and i > 1: vv = AAS[i-2][1] if v < vv: l[vv] = False print(count)