n = int(input()) a = list(map(int, input().split())) sorted_with_indices = sorted([(val, idx) for idx, val in enumerate(a)], key=lambda x: (x[0], x[1])) pos = [pair[1] for pair in sorted_with_indices] required = set() for i in range(n - 1): if pos[i] > pos[i + 1]: required.add(max(pos[i], pos[i + 1])) print(len(required))