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