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