#include #include using namespace std; const int kMAX_N = 100010; int N; int a[kMAX_N]; void Solve() { reverse(a, a + N); int ans = 0, s = 0, num = N; while (s < N) { int t = s; while (t < N && a[t] != num) { ans++; t++; } num--; s = t + 1; } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } Solve(); return 0; }