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