n = int(input()) a = list(map(int, input().split())) n = n for i in a[::-1]: if i == n: n = n-1 print(n)