import sys def main(): N = int(input()) A = list(map(int, input().split())) n = N for a in reversed(A): if a == n: n -= 1 print(n) main()