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