N = int(input()) a = list(map(int,input().split())) bottom = len(a) for i in range(len(a)+1)[::-1]: if a[i] == bottom: bottom -= 1 print(bottom)