n = int(input()) alst = list(map(int, input().split())) now = n ans = n for num in alst[::-1]: if num == now: ans -= 1 now -= 1 print(ans)