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