n = int(input()) a = list(map(int,input().split())) cnt = 0 j = n for i in reversed(a): if i == j: cnt += 1 j -= 1 print(n - cnt)