n = int(input()) a = list(map(int,input().split())) b = a[::-1] j = 0 c = 0 for i in range(n): if b[i] == n-j: j += 1 print(n-j)