def solve(area): next_area = list(area) if len(next_area) <= 1: return 0 elif len(next_area) == 2: return 1 count = 0 while True: max_ind = next_area.index(max(next_area)) min_ind = next_area.index(min(next_area)) if max_ind == min_ind: break next_area = next_area[0:min_ind] if max_ind < min_ind else next_area[min_ind + 1: len(next_area)] count += 1 max_ind = area.index(max(area)) if max_ind == 2: count += 1 elif max_ind > 2: count += solve(area[0:max_ind]) if (len(area) - max_ind) == 3: count += 1 elif (len(area) - max_ind) > 3: count += solve(area[max_ind + 1: len(area)]) return count N = int(input()) data = input().split() Input = [int(s) for s in data] print(solve(Input))