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