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