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