n=m=int(input()) for i in reversed(input().split()): if int(i)==m:m-=1 print(m)