#include #include using namespace std; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } bool b = false; int cnt = 0; for (int i = N - 1; i >= 0; i--) { if (!b) { if (A[i] == N) { b = true; cnt++; } } else { if (A[i] == N - cnt) { cnt++; } } } cout << N - cnt << endl; getchar(); getchar(); return 0; }