#include #include using namespace std; int main() { int N, maxi; vector a; cin >> N; for (int i = 0, x, max = 0; i < N; ++i) { cin >> x; a.push_back(x); if (max < x) max = x, maxi = i; } int res = N; if (maxi == N-1) { for (int i = N-1, x = N-1; i >= 0; --i) { if (a[i] == x - 1) --x, --res; } } cout << res << endl; return 0; }