N = int(input()) a = list(map(int,input().split())) bottom = len(a) for t in reversed(a): if t == bottom: bottom -= 1 print(bottom)