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