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