n = int(input()) s = list(map(int, input().split())) x =n for i in reversed(s): if i !=x: x=x else: x -=1 print(x)