N = int(input()) A = list(map(int, input().split())) now = N ans = N for a in reversed(A): if a == now: ans -= 1 now -= 1 print(ans)