import numpy as np def solve(area): next_area = area count = 0 while True: max_ind = np.argmax(next_area) min_ind = np.argmin(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: next_area.shape[0]] count += 1 max_ind = np.argmax(area) if max_ind == 2: count += 1 elif max_ind > 2: count += solve(area[0:max_ind]) if (area.shape[0] - max_ind) == 2: count += 1 elif (area.shape[0] - max_ind) > 2: count += solve(area[max_ind + 1: area.shape[0]]) return count N = int(input()) input_np = np.array(input().split()).astype(np.int32) print(solve(input_np))