N = int(input()) l = list(map(int, input().split())) l.reverse() sum = 0 while len(l) > 0: num_max = max(l) for i in range(len(l)): if l[i] == num_max: sum += i l = l[i + 1:] break print(sum)