N = int(input()) A = list(map(int, input().split(' '))) n = N count = 0 i = 0 for a in reversed(A): if a == n: count += i i = 0 n -= 1 else: i += 1 print(count)