n = int(input()) a = list(map(int, input().split())) x = n cnt = 0 for i in reversed(a): if i == x: cnt += 1 x -= 1 print(n - cnt)