blocks_num = int(input()) blocks = [int(i) for i in input().split(' ')] searching_num = blocks_num count = 0 for i in reversed(blocks): if i == searching_num: count += 1 searching_num -= 1 answer = blocks_num - count print(answer)