N = input() a = map(int , raw_input().split()) count = 0 look = N for i in range(N): if look == a[N - i - 1]: look -= 1 count += 1 print N - count